SpringCloud版本區別java
1、maven依賴配置,SpringCloud目前有四個版本,經測試Camden,Dalston兩個版本構建Eureka正常,其它兩版本存在jar依賴問題,因此選取Dalstont版本,目前採用最新和SR5 依賴以下spring
<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"> <modelVersion>4.0.0</modelVersion> <groupId>com.pkfare</groupId> <artifactId>eureka</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/java</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
2、Eureka啓動,propertySource加載配置文件路徑,默認引入resources下的application.propertiesapache
@SpringBootApplication @EnableEurekaServer @PropertySource("file:/var/server-config/eureka/config.properties") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
3、Eureka的配置安全
1.獨立模式 registerWithEureka,fetchRegistry關閉註冊app
spring.application.name=eureka-server server.port=8889 eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false
2.集羣模式 eureka.client.serviceUrl.defaultZone相互註冊實現集羣化maven
spring.application.name=eureka-server server.port=8889 eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8888/eureka/
3.安全認證模式 defaultZone必定要配置,用於服務地址註冊,默認不配啓用8761端口spring-boot
spring.application.name=eureka-server server.port=8889 eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false security.basic.enable=true security.user.name=vito security.user.password=123456 eureka.client.serviceUrl.defaultZone=http://vito:123456@127.0.0.1:8889/eureka/ eureka.client.healthcheck.enabled=true