spring-cloud-netflix-eureka-server
阿新 • • 發佈:2020-10-12
一、構建springcloud父pom工程,管理版本
pom.xml
<?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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR8</spring-cloud.version> </properties> <groupId>lf.liyouyou</groupId> <artifactId>spring-cloud-netflix-demo</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> </modules> <dependencies> </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> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
二、new module,選中Spring Initialzr
點選next,編輯工程名稱、包,點選next,到spring元件頁
根據自己對的需要勾選對應的元件,我們選擇如下構建配置中心
點選next,點選finish。
1.生成的pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>lf.liyouyou</groupId> <artifactId>spring-cloud-netflix-demo</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>lf.liyouyou</groupId> <artifactId>spring-cloud-eureka-server</artifactId> <version>0.0.1-SNAPSHOT</version> <name>spring-cloud-eureka-server</name> <description>Demo project for Spring Boot</description> <dependencies> <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> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>
2.啟動類中添加註解
package lf.liyouyou.springcloudeurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class SpringCloudEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudEurekaServerApplication.class, args);
}
}
3.配置application.properties
spring.application.name=spring-cloud-netflix-eureka server.port=8000 #禁止自己當做服務註冊--表示是否將自己註冊到Eureka Server,預設為true。 eureka.client.register-with-eureka=false #遮蔽註冊資訊--表示是否從Eureka Server獲取註冊資訊,預設為true eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
啟動專案,訪問http://localhost:8000/檢視eureka面板