解析spring cloud ouath2中的Eureka
老生常談的配置 但是還是需要說明一下
EurekaApplication
@EnableEurekaServer指定為server端
@EnableEurekaServer@SpringBootApplicationpublic class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } }
WebSecurityConfig
看到這眼熟不呢 沒錯(cuò) Eureka也開啟spring security 在訪問前臺頁面時(shí)也需要輸入賬號密碼
@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: info
pom.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>
當(dāng)訪問localhost:7001 出現(xiàn)下圖 需要填寫賬號密碼
在其他服務(wù)注冊時(shí) 也需要指定賬號密碼
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
到此這篇關(guān)于spring cloud ouath2中的Eureka的文章就介紹到這了,更多相關(guān)spring cloud ouath2內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 在Android中使用WebSocket實(shí)現(xiàn)消息通信的方法詳解2. Yii2.0引入CSS,JS文件方法3. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析4. Nginx+php配置文件及原理解析5. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解6. 常用數(shù)據(jù)庫JDBC連接寫法(轉(zhuǎn)摘)7. Python importlib動態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼8. JavaMail 1.4 發(fā)布9. 淺談python出錯(cuò)時(shí)traceback的解讀10. vue使用webSocket更新實(shí)時(shí)天氣的方法
