皇冠新体育APP

IT技术之家

3.Sping Cloud组件之Eureka_java好学生

上架事件:2023-08-24 15:00:26 大数据 38次 标签:java intellij-idea maven spring boot 皇冠新体育APP:spring cloud Powered
Sping Cloud组件之Eureka...

3.1.创建Springboot项目

3.2.项目pom依赖
<?xmlversion="1.0" encoding="UTF-8"?> <projectxmlns="//maven.apache.org/POM/4.0.0"xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="//maven.apache.org/POM/4.0.0 " target="_blank">//maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.9.RELEASE</version> <relativePath/><!-- lookup parent from repository --> </parent> <groupId>com.cssl</groupId> <artifactId>kgc47eureka6060</artifactId> <version>0.0.1-SNAPSHOT</version> <name>kgc47eureka6060</name> <description>Demo project for Spring Boot</description> ? <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR10</spring-cloud.version> </properties> ? <dependencies> <!--登陆服务培训中心服务培训端依赖症--> <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-security</artifactId> </dependency> </dependencies> ? </project>
3.3.application.yml配置
server: port: 6060 #Eureka Server和Tomcat表层(不是默认值8761,Tomcat8080) spring: application: name: eureka #应用软件标题,也可以说是微服务培训标题,不写正常空 security: #注册的到eureka应该用户账户名和密匙 user: name: admin password: 123 ? eureka: server: enable-self-preservation: false #不可用保护好,锁定true eviction-interval-timer-in-ms: 10000 #清扫连续(默认值是60*1000) client: fetch-registry: false #是否是从eureka server想要高效率的获取到服务于数据信息,默认要求true register-with-eureka: false #是否能够向eureka server注册帐号,默认设置true service-url: defaultZone: //localhost:6060/eureka/ #申请注册门店地址(不相配设置8761)
3.4.启动类:
@SpringBootApplication @EnableEurekaServer publicclassKgc47eureka6060Application { ? publicstaticvoidmain(String[] args) { SpringApplication.run(Kgc47eureka6060Application.class, args); } ? }

3.5.设置csr检查(坑)
在2.0以来,要求下载这一进行检查如何设置,要不然eureka-client时未注册成功到eureka-server上前 @EnableWebSecurity publicclassWebSecurityConfigextendsWebSecurityConfigurerAdapter { ? @Override protectedvoidconfigure(HttpSecurityhttp) throwsException { http.csrf().disable(); //引魂灯应用csr验正 super.configure(http); } }
3.6.运行访问

3.7.创建eureka-client客户端项目(除了eureka server注册中心以外其他都是eureka-客户端(都要导web包,其他包情况而定))
确实是开启springboot活动,只能在首选引擎的目光

3.8.项目pom依赖
<?xmlversion="1.0" encoding="UTF-8"?> <projectxmlns="//maven.apache.org/POM/4.0.0"xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="//maven.apache.org/POM/4.0.0 " target="_blank">//maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.9.RELEASE</version> <relativePath/><!-- lookup parent from repository --> </parent> <groupId>com.cssl</groupId> <artifactId>kgc47consumer8090</artifactId> <version>0.0.1-SNAPSHOT</version> <name>kgc47consumer8090</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR10</spring-cloud.version> </properties> <dependencies> <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-client</artifactId> </dependency> </dependencies> </project>
3.9.application.yml配置
带来者: server: port: 7001 ? spring: application: name: provider ? eureka: client: register-with-eureka: true #向eurek server 登陆 fetch-registry: true #得到企业信息全部 service-url: defaultZone: //admin:123@localhost:6001/eureka/ #留意用户组名和PIN码 @
3.10.启动类
@SpringBootApplication @EnableEurekaClient与@EnableDiscoveryClient(整个注解是可以向任何的申请公司引入)如此 publicclassKgc47consumer8090Application { ? publicstaticvoidmain(String[] args) { SpringApplication.run(Kgc47consumer8090Application.class, args); } ? }
3.11.查看eureka主页

访问 //127.0.0.1:6060 ,在applications中显示客户端信息