解析spring cloud ouath2中的Eureka

网友投稿 243 2022-11-03


解析spring cloud ouath2中的Eureka

老生常谈的配置 但是还是需要说明一下

EurekaApplication

@EnableEurekaServer指定为server端

@EnableEurekaServer

@SpringBootApplication

public class EurekaApplication {

public static void main(String[] args) {

SpringApplication.run(EurekaApplication.class, args);

}

}

WebSecurityConfig

看到这眼熟不呢 没错 Eureka也开启spring security 在访问前台页面时也需要输入账号密码

@Configuration

@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override

protected void configure(HttpSecurity http) throws Exception {

super.configure(http);

http.csrf().disable().httpBasic();

}

}

application.yml

security:user以下配置的账号密码 在访问页面需要输入的

server:

port: 7001

sMJhWcWWUpring:

application:

name: eureka

security:

user:

name: admin

password: xxxxxxxxxx

eureka:

client:

fetch-registry: false

register-with-eureka: false

service-url:

defaultZone: http://admin:Xk38CNHigBP5jK75@localhost:5001/eureka

instance:

hostname: localhost

prefer-ip-address: true

logging:

config: classpath:logback.xml

level:

root: info

pom.xml

org.springframework.boot

spring-boot-starter-security

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.security

spring-security-test

test

当访问localhost:7001 出现下图 需要填写账号密码

在其他服务注册时 也需要指定账号密码

eureka:

instance:

hostname: ${spring.cloud.client.ip-address}

prefer-ip-address: true

instance-id: ${eureka.instance.hostname}:${server.port}

//与server一致

client:

security:

basic:

user: admin

password: xxxxxxxxxxx

service-url:

defaultZone: http://${eureka.client.security.basic.user}:${eureka.client.security.basic.password}@localhost:7001/eurMJhWcWWUeka


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:顺风快递查询API(顺风快递查询号码查询物流)
下一篇:网络查询API(网络查询财产申请书)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~