当我通过Spring Boot and Access localhost:8080部署Spring应用程序时,我必须进行身份验证,但是用户名和密码是什么,或者我如何设置它呢?我试图将此添加到我的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中有该选项,则应该会显示如下日志(log)控制台消息:

Using default security password: ce6c3d39-8f20-4a41-8e01-803166bb99b6

在浏览器提示中,您将导入用户user和控制台中打印的密码.

或者,如果您想配置spring安全性,可以查看Spring Boot secured example

Security节的Spring Boot Reference documentation中说明了这一点,它表示:

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相关问答推荐

Spring Boot找不到Mapper bean

将具有多个未知字段的SON映射到Java POJO

Android视图覆盖不阻止点击它后面的控件

强制Mockito返回null而不是emtpy list

如何在返回bigint []值的子查询中使用any?

Junit with Mockito for java

嵌入式ActiveMQ Artemis Web控制台加载错误

使用Mockito进行的Junit测试失败

对于亚洲/香港,使用ResolverStyle.STRICT的LocalDate.parse返回意外结果

如何让JVM在SIGSEGV崩溃后快速退出?

%This内置函数示例

由于在生成器模式中使用泛型,lambda表达式中的返回类型错误

如何在Spring Boot中创建可以将值传递给配置的&Enable&Quot;注释?

垃圾收集时间长,会丢弃网络连接,但不会在Kubernetes中反弹Pod

EXCEL中的公式单元格显示#NAME?

在Java中将.GRF转换为图像文件

在单例类上获取Java锁,了解原因

验证没有';t work on Hibernate Entity';s字段

";home/runner/work/中没有文件...匹配到[**/pom.xml];Maven项目的构建过程中出现错误

java.lang.ClassCastException:com.google.firebase.FirebaseException无法转换为com.google.fire base.auth.FirebaseAuthException