Eureka Serverjava
@SpringBootApplication@EnableEurekaServerpublic class EurekaApplication {public static void main(String[] args) {SpringApplication.run(EurekaApplication.class, args);}}
spring:application:name: microservice-discovery-eureka-ha---spring:profiles: peer1 # 指定profile=peer1server:port: 8761eureka:instance:hostname: peer1 # 指定當profile=peer1時,主機名是peer1client:serviceUrl:defaultZone: http://localhost:8762/eureka/ # 將本身註冊到peer2這個Eureka上面去# server:# enable-self-preservation: false---spring:profiles: peer2server:port: 8762eureka:instance:hostname: peer2client:serviceUrl:defaultZone: http://localhost:8761/eureka/# server:# enable-self-preservation: falsejava -jar microservice-discovery-eureka-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1java -jar microservice-discovery-eureka-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2
Eureka Clientspring
@EnableDiscoveryClient@SpringBootApplicationpublic class ProviderUserApplication {public static void main(String[] args) {SpringApplication.run(ProviderUserApplication.class, args);}}
server:port: 8000spring:application:name: microservice-provider-userjpa:generate-ddl: falseshow-sql: truehibernate:ddl-auto: nonedatasource: # 指定數據源platform: h2 # 指定數據源類型schema: classpath:schema.sql # 指定h2數據庫的建表腳本data: classpath:data.sql # 指定h2數據庫的數據腳本logging: # 配置日誌級別,讓hibernate打印出執行的SQLlevel:root: INFOorg.hibernate: INFOorg.hibernate.type.descriptor.sql.BasicBinder: TRACEorg.hibernate.type.descriptor.sql.BasicExtractor: TRACEeureka:client:serviceUrl:defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/instance:prefer-ip-address: true //註冊IP到Server,默認爲host namelease-renewal-interval-in-seconds: 1lease-expiration-duration-in-seconds: 2
小結sql
security.basic.enabled=true //開啓基於HTTP basic的認證security.user.name=xxxsecurity.user.password=xxx