通过 localhost:8080 访问 Spring Boot 应用程序时出错
Posted
技术标签:
【中文标题】通过 localhost:8080 访问 Spring Boot 应用程序时出错【英文标题】:error accessing spring boot application via localhost:8080 【发布时间】:2021-11-15 21:21:28 【问题描述】:我尝试访问 localhost:8080/hello 但呼吁 localhost:8080/login 唯一显示的是网络状态的状态代码 302,并显示 hello.html 没有启动器,启动器 hello 正在登录
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
文件(如果你使用maven)
请分享您的 application.properties。
@mr155 pastebin.com/9a3DXsXC
【参考方案1】:
如果您不想使用安全性,只需从您的 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
【讨论】:
以上是关于通过 localhost:8080 访问 Spring Boot 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章