通过 localhost:8080 访问 spring 启动应用程序时出错
error accessing spring boot application via localhost:8080
我尝试访问 localhost:8080/hello 但请求 localhost:8080/login 唯一显示的是网络状态上的状态代码 302,并显示 hello.html 没有发起者和发起者你好正在登录
package com.example.biblioteca;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BibliotecaApplication {
public static void main(String[] args) {
SpringApplication.run(BibliotecaApplication.class, args);
}
}
Controller class
package com.example.biblioteca.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloControler {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
html file:
<html>
<head>
<meta charset ="UTF-8"/>
</head>
<body>
hello working
</body>
</html>
如果您不想使用安全性,只需从您的 pom.xml
文件中删除或评论此依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
when you use spring-security
you have to pass the authentication
before any action.
如果您想使用安全性,请将此安全配置添加到 application.properties
文件:
spring.security.user.name=custom-username
spring.security.user.password=custom-password
我尝试访问 localhost:8080/hello 但请求 localhost:8080/login 唯一显示的是网络状态上的状态代码 302,并显示 hello.html 没有发起者和发起者你好正在登录
package com.example.biblioteca;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BibliotecaApplication {
public static void main(String[] args) {
SpringApplication.run(BibliotecaApplication.class, args);
}
}
Controller class
package com.example.biblioteca.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloControler {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
html file:
<html>
<head>
<meta charset ="UTF-8"/>
</head>
<body>
hello working
</body>
</html>
如果您不想使用安全性,只需从您的 pom.xml
文件中删除或评论此依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
when you use
spring-security
you have to pass the authentication before any action.
如果您想使用安全性,请将此安全配置添加到 application.properties
文件:
spring.security.user.name=custom-username
spring.security.user.password=custom-password