Spring Cloud例子--Eureka Server工程的搭建(idea)

 

我是用的IDE是Intellij idea ultimate 2018.1版本,jdk1.8,apache-maven-3.2.2。然后开始创建一个eureka server的工程,操作如下:
1、首先创建主maven工程
选择maven,取消选中Create from archetype。
点击‘Next’,填写GroupId和ArtifactId。

 

 

点击‘Next’
点击‘Finish'

 

2、创建子项目

 

 

在主项目名称上右键->New->Module,选择’Spring Initializr‘
点击’Next',修改某些内容,如图所示:

 

 

点击‘Next’,选择‘Cloud Discovery'->Eureka Server

 

 

点击’Next'

 

 

点击‘Finish',生成的目录结构如图所示:

 

 

在主工程的pom.xml中添加子项目的模块,如图:

 

 

把子工程中的application.properties文件名改成application.yml,因为感觉yml文件比较好用。application.yml中的内容如下:

 

 

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
然而发现org.springframework.cloud中的依赖有问题,如图:

 

 

这是由于在maven中央库中找不到对应Finchley.RC2版本的spring-cloud-dependency,那就改成Edgware.SR3吧,然后就不报错了。
然后在EurekaServerApplication中添加注解@EnableEurekaServer

 

 

Run 'EurekaServerApplication'
然而发现运行有报错:
 

java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

 at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
 at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
 at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
 at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
 at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
 at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
 at com.springcloudexample.eureka.eurekaserver.EurekaServerApplication.main(EurekaServerApplication.java:12)
Process finished with exit code 1

 

 

原因可能出在spring boot的版本和spring cloud的版本有冲突,解决方案是:把spring boot的版本降低为1.5.3.RELEASE
然后启动就正常了。

 

 

通过这个url可以访问eureka server的管理页面:http://localhost:8761/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值