微服务发现组件Eureka:微服务注册
生活随笔
收集整理的這篇文章主要介紹了
微服务发现组件Eureka:微服务注册
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#注冊到eureka的服務地址
eureka:client:service-url:defaultZone: http://localhost:6868/eureka/
#服務配置
server:port: 9001
#spring配置
spring:#1.應用配置application:name: ihrm-company #指定服務名#2.數據庫連接池datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8username: rootpassword: 123456#3.JPAjpa:database: MySQLshow-sql: trueopen-in-view: trueredis:host: localhostport: 6379password: 123456
package com.learn.company;import com.learn.common.utils.IdWorker;
import com.learn.common.utils.JwtUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;//1.配置springboot的包掃描
@SpringBootApplication(scanBasePackages = "com.learn")
//2.配置jpa注解的掃描
@EntityScan(value="com.learn.domain.company")
//3.注冊到eureka
@EnableEurekaClient
public class CompanyApplication {/*** 啟動方法*/public static void main(String[] args) {SpringApplication.run(CompanyApplication.class,args);}@Beanpublic JwtUtils jwtUtils() {return new JwtUtils();}@Beanpublic IdWorker idWorker() {return new IdWorker();}
}
package com.learn.system;import com.learn.common.utils.IdWorker;
import com.learn.common.utils.JwtUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;//1.配置springboot的包掃描
@SpringBootApplication(scanBasePackages = "com.learn")
//2.配置jpa注解的掃描
@EntityScan(value="com.learn.domain.system")
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class SystemApplication {/*** 啟動方法*/public static void main(String[] args) {SpringApplication.run(SystemApplication.class,args);}@Beanpublic IdWorker idWorker() {return new IdWorker();}@Beanpublic JwtUtils jwtUtils() {return new JwtUtils();}//解決no session@Beanpublic OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {return new OpenEntityManagerInViewFilter();}
}
#注冊到eureka的服務地址
eureka:client:service-url:defaultZone: http://localhost:6868/eureka/
#服務配置
server:port: 9002
#spring配置
spring:#1.應用配置application:name: ihrm-system #指定服務名#2.數據庫連接池datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8username: rootpassword: 123456#3.JPAjpa:database: MySQLshow-sql: trueopen-in-view: trueredis:host: localhostport: 6379password: 123456
jwt:config:key: saas-ihrmttl: 3600000
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>learn_parent</artifactId><groupId>com.learn</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>learn_employee</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency></dependencies><build><plugins><!--被打包項目必須配置項--><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!--配置為執行--><classifier>exec</classifier></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!-- 指定該Main Class為全局的唯一入口 --><mainClass>com.learn.employee.EmployeeApplication</mainClass><layout>ZIP</layout></configuration><executions><execution><goals><goal>repackage</goal><!--可以把依賴的包都打包到生成的Jar包中--></goals></execution></executions></plugin></plugins></build>
</project>
#微服務注冊到eureka配置
eureka:client:service-url:defaultZone: http://localhost:6868/eureka/
server:port: 9003
spring:application:name: ihrm-employee #指定服務名datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8username: rootpassword: 123456jpa:database: MySQLshow-sql: trueopen-in-view: trueredis:host: localhostport: 6379password: 123456
package com.learn.employee;import com.learn.common.utils.IdWorker;
import com.learn.common.utils.JwtUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;@SpringBootApplication(scanBasePackages = "com.learn")
@EntityScan("com.learn.domain.employee")
@EnableEurekaClient
public class EmployeeApplication {public static void main(String[] args) {SpringApplication.run(EmployeeApplication.class, args);}@Beanpublic IdWorker idWorkker() {return new IdWorker(1, 1);}@Beanpublic JwtUtils jwtUtil() {return new JwtUtils();}
}
package com.learn.eureka;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;/*** eureka服務端的啟動類*/
@SpringBootApplication
@EnableEurekaServer //開啟eureka服務端配置
public class EurekaServer {public static void main(String[] args) {SpringApplication.run(EurekaServer.class,args);}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>learn_parent</artifactId><groupId>com.learn</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>learn_system</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common_model</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency></dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>learn_parent</artifactId><groupId>com.learn</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>learn_company</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.learn</groupId><artifactId>learn_common_model</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency></dependencies>
</project>
?
總結
以上是生活随笔為你收集整理的微服务发现组件Eureka:微服务注册的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微服务发现组件Eureka:简介以及Eu
- 下一篇: 微服务调用组件Feign:简介以及搭建环