时间:2021-05-19
老生常谈的配置 但是还是需要说明一下
EurekaApplication
@EnableEurekaServer指定为server端
@EnableEurekaServer@SpringBootApplicationpublic class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } }WebSecurityConfig
看到这眼熟不呢 没错 Eureka也开启spring security 在访问前台页面时也需要输入账号密码
@Configuration@EnableWebSecuritypublic 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: 7001spring: application: name: eureka security: user: name: admin password: xxxxxxxxxxeureka: client: fetch-registry: false register-with-eureka: false service-url: defaultZone: http://admin:Xk38CNHigBP5jK75@localhost:5001/eureka instance: hostname: localhost prefer-ip-address: truelogging: config: classpath:logback.xml level: root: infopom.xml
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> </dependencies>当访问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/eureka到此这篇关于spring cloud ouath2中的Eureka的文章就介绍到这了,更多相关spring cloud ouath2内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
1.添加依赖 org.springframework.cloud spring-cloud-starter-netflix-eureka-client2.添
Spring-cloud-eureka使用feign调用服务接口的具体方法,供大家参考,具体内容如下基于spring-boot2.0以上版本完成的微服务架构po
1.官方文档https://cloud.spring.io/spring-cloud-static/spring-cloud-openfeign/2.2.2.R
文档地址https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-ali
引入依赖org.springframework.cloudspring-cloud-dependencies${spring-cloud.version}pom