这个版本的eureka ,配置用户名密码 与其他版本 有所不同
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
1.首先是配置文件 修改:
原来的配置方式
#security:
# basic:
# enabled: true
# user:
# name: user
# password: password
现在的配置方式
spring:
security:
user:
name: user
password: password
2.pom文件
<!--添加用户名密码 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
3.
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
http.csrf().disable(); //关闭csrf
//注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,如果是form方式,不能使用url格式登录
http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); //开启认证
}
}
所以要在程序里 写一个配置类
这样用户名 密码就可以添加上了
如果不写那个配置类 ,就会成这个样子