创建Maven项目
- groupId:公司名+项目名,com.wsh.springcloudFramework
- artifactId: 项目名+模块名称, springcloudframework
一.搭建注册中心
- 添加pom.xml,注意版本问题,这个应该是最新的了
<groupId>com.wsh.springcloudFramework</groupId>
<artifactId>springcloudframework</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.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>1.8</java.version>
</properties>
<dependencies>
<dependency>
<!--eureka server -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<!-- spring boot test-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
- 增加application.yml,idea直接创建file文件,然后更改后序
#端口号
server:
port: 8888
#eureka配置
eureka:
instance:
#注册中心ip地址
hostname: localhost
client:
#是否注册到eureka
registerWithEureka: false
#是否检测服务信息
fetchRegistry: false
#注册地址
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class mainApplication {
public static void main(String[] args) {
SpringApplication.run(mainApplication.class, args);
}
}
- 然后访问http://localhost:8888/,就可以看到效果了
