解析spring cloud ouath2中的Eureka
老生常談的配置 但是還是需要說明一下
EurekaApplication
@EnableEurekaServer指定為server端
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
WebSecurityConfig
看到這眼熟不呢 沒錯(cuò) Eureka也開啟spring security 在訪問前臺(tái)頁面時(shí)也需要輸入賬號(hào)密碼
@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以下配置的賬號(hào)密碼 在訪問頁面需要輸入的
server: port: 7001 spring: 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
<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)下圖 需要填寫賬號(hào)密碼

在其他服務(wù)注冊(cè)時(shí) 也需要指定賬號(hào)密碼
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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java獲取IP地址及對(duì)應(yīng)的歸屬地的方法詳解
這篇文章主要為大家詳細(xì)介紹了如何利用Java獲取IP地址及對(duì)應(yīng)的歸屬地,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-03-03
java8如何根據(jù)某一屬性條件快速篩選list中的集合
這篇文章主要介紹了java8如何根據(jù)某一屬性條件快速篩選list中的集合,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
使用spring stream發(fā)送消息代碼實(shí)例
這篇文章主要介紹了使用spring stream發(fā)送消息代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
簡(jiǎn)單了解JAVA內(nèi)存區(qū)域效果知識(shí)
這篇文章主要介紹了簡(jiǎn)單了解JAVA內(nèi)存區(qū)域效果知識(shí),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10

