使用Tomcat启动Spring

使用Tomcat启动Spring

本文介绍了使用Tomcat启动Spring Boot时的用户名和密码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过Spring Boot部署我的Spring应用程序并访问 localhost:8080 我必须进行身份验证,但是用户名和密码是什么或者如何设置它?我尝试将此添加到我的 tomcat-users 文件中,但它不起作用:

When I deploy my Spring application via Spring Boot and access localhost:8080 I have to authenticate, but what is the username and password or how can I set it? I tried to add this to my tomcat-users file but it didn't work:

<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的依赖:

And this is the Tomcat dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

如何在 localhost:8080 上进行身份验证?

How do I authenticate on localhost:8080?

推荐答案

我认为您的类路径上有Spring Security,然后Spring安全性会自动配置为默认用户并生成密码

I think that you have Spring Security on your class path and then spring security is automatically configured with a default user and generated password

请查看您的pom.xml文件:

Please look into your pom.xml file for:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

如果你的pom中有这个,那么你应该有这样的日志控制台消息:

If you have that in your pom than you should have a log console message like this:

使用默认安全密码:ce6c3d39-8f20-4a41-8e01-803166bb99b6

在浏览器提示符下,您将导入用户用户以及在控制台中打印的密码。

And in the browser prompt you will import the user user and the password printed in the console.

或者,如果您想配置弹簧安全性,可以查看

Or if you want to configure spring security you can take a look at Spring Boot secured example

部分,它表明:

It is explained in the Spring Boot Reference documentation in the Security section, it indicates:

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

这篇关于使用Tomcat启动Spring Boot时的用户名和密码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 06:42