【问题标题】:error accessing spring boot application via localhost:8080通过 localhost:8080 访问 Spring Boot 应用程序时出错
【发布时间】: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。

标签: java spring-boot http networking localhost


【解决方案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

【讨论】:

    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 2021-04-19
    • 2016-12-29
    • 2017-02-08
    • 2010-12-02
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多