我試圖訪問localhost:8080/hello,但上訴localhost:8080/login,唯一顯示的是網路狀態代碼302,并顯示hello.html沒有發起人,發起人hello在login上
。 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)。
}
}
控制器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檔案。
<html>
<head>
<meta charset ="UTF-8"/span>/>
</head>
<body>
你好,正在作業
</body>
</html>
uj5u.com熱心網友回復:
如果你不想使用安全,只需從你的pom.xml檔案中洗掉或注釋這個依賴關系:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
當你使用
spring-security時,你必須在任何行動之前通過認證。 在任何行動之前。
如果你想使用安全,在application.properties檔案中添加這個安全配置:
spring.security.user.name=custom-username
spring.security.user.password=custom-password
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/333319.html
標籤:
