标签:none mvn def jaxb .com dep snapshot 1.0 one
windows10,IntelliJ IDEA
<?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"> <modelVersion>4.0.0</modelVersion> <groupId>peter.test</groupId> <artifactId>singleeureka</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>singleeureka</name> <description>Demo project for Spring Cloud Eureka</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>10</java.version> <spring-cloud.version>Finchley.RELEASE</spring-cloud.version> </properties> <dependencies> <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-netflix-eureka-server</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
在IDEA中,直接启动调试,会报错,添加进这个依赖就可以执行了。
注释掉 spring-boot-starter-test 是因为暂时不需要单元测试。
spring.application.name=spring-cloud-eureka
server.port=9232
eureka.instance.hostname=peterhost1
eureka.client.service-url.defaultZone=http://peterhost2:9232/eureka/
debug=true
@EnableEurekaServer @SpringBootApplication public class SingleeurekaApplication { public static void main(String[] args) { SpringApplication.run(SingleeurekaApplication.class, args); } }
打包
mvn clean package
运行并访问
同单节点一样
使用yml文件可以在命令启动时指定profile
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost1
server:
port: 9000
eureka:
instance:
hostname: peterhost1
client:
service-url:
defaultZone: http://peterhost2:9001/eureka/,http://peterhost3:9002/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost2
server:
port: 9001
eureka:
instance:
hostname: peterhost2
client:
service-url:
defaultZone: http://peterhost3:9002/eureka/,http://peterhost1:9000/eureka/
---
spring:
application:
name: spring-cloud-eureka
profiles: peterhost3
server:
port: 9002
eureka:
instance:
hostname: peterhost3
client:
service-url:
defaultZone: http://peterhost1:9000/eureka/,http://peterhost2:9001/eureka/
作为高可用,第1个节点指定默认的zone为第2个和第3个节点,以此类推。
@EnableEurekaServer @SpringBootApplication public class ThreeeurekaApplication { public static void main(String[] args) { SpringApplication.run(ThreeeurekaApplication.class, args); } }
打包
同上
运行并访问
java -jar 路径\threeeureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peterhost1 java -jar 路径\threeeureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peterhost2 java -jar 路径\threeeureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peterhost3
配置文件中是按照hostname进行配置的,有时我们想直接使用ip,可如下设置:
eureka.instance.prefer-ip-address=true
eureka.ip-address=xxx.xxx.xxx.xxx
这样在Producer或者Consumer获取Eureka中的服务后,如使用Fegin等组件时则会使用ip进行访问。
标签:none mvn def jaxb .com dep snapshot 1.0 one
原文地址:https://www.cnblogs.com/dopeter/p/9399156.html