Spring Assistant创建Eureka服务的项目

1,如果idea没有Spring Assistant插件,先下载插件file--->settings--->Plugins--->Spring Assistant安装重启idea

2,
image.png

3,填写自己项目的信息,我选择使用的是maven
image.png

4,
image.png

5,然后在pom.xml文件里面加入依赖:
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

4,修改启动类,添加Eureka Server的annotation,@EnableEurekaServer


image.png

5,在application.properties里面加入以下内容

#端口号
server.port=8081
eureka.instance.hostname=localhost
#向注册中心注册服务
eureka.client.registerWithEureka=false
# 检索服务
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
#在Eureka服务器获取不到集群里对等服务器上的实例时,需要等待的时间
server.waitTimeInMsWhenSyncEmpty=0
#自我保护模式
server.enableSelfPreservation=false

5,启动Eureka Server


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容