通过 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 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章
在tomcat下部署 在webapps下的war包 的项目能不能直接通过localhost:8080访问不加项目名,急!在线等
如何解决这个“http://localhost:8080”已被 CORS 策略阻止:对预检请求的响应未通过 vueJS 中的访问控制?
eclipse配置tomcat,访问http://localhost:8080出现404错误
本地虚拟机的tomcat, localhost:8080无法访问, 127.0.0.1:8080也无法访问, ip:8080可以访问,怎么办?
从 localhost:4200 访问 localhost:8080 的 XMLHttpRequest 已被 CORS 策略阻止
我可以从浏览器“http://localhost:8080/”访问,但不能访问“my_private_ip:8080/”