导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-security</artifactId>
</dependency>
使用随机密码认证登录
1、application.yml文件中,加入以下配置:
security:
basic:
enabled: true #是否生成随机密码。 为true:在项目启动时会生成随机密码

2、输入随机密码,账号默认是user

登录成功
自定义账户密码认证登录
1、application.yml文件中,加入以下配置:
security:
basic:
enabled: false #是否生成随机密码
user:
name: root
password: 123456
2、启动程序,访问http://localhost:8001/ 输入账户root,密码123456


本文介绍了如何在Spring Cloud Security中配置随机密码认证和自定义账户密码认证。通过设置`security.basic.enabled`为true,系统将在启动时生成随机密码。默认用户名为'user'。若设置为false,则可以自定义用户名(如'root')和密码(如'123456')。启动应用后,用户可通过指定的账号密码登录。
1847

被折叠的 条评论
为什么被折叠?



