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