当我通过 Spring Boot 部署 Spring 应用程序并访问 localhost:8080 时,我必须进行身份验证,但用户名和密码是什么或者如何设置?我尝试将其添加到我的 tomcat-users
文件中,但它不起作用:
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
这是应用程序的起点:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
这是 Tomcat 依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
如何在 localhost:8080
上进行身份验证?
最佳答案
我认为您的类路径上有 Spring Security,然后 Spring Security 会自动配置默认用户和生成的密码
请查看您的 pom.xml 文件:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
如果你的 pom 中有这样的内容,那么你应该有这样的日志控制台消息:
使用默认安全密码:ce6c3d39-8f20-4a41-8e01-803166bb99b6
在浏览器提示中,您将导入用户user
以及控制台中打印的密码。
或者如果你想配置 spring security 你可以看看 Spring Boot secured example
Security 中的 Spring Boot 引用文档对此进行了解释。部分,它表示:
The default AuthenticationManager has a single user (‘user’ username and random password, printed at `INFO` level when the application starts up)
Using default security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35
关于java - 使用Tomcat启动Spring Boot时的用户名和密码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57738925/