今天在学习eureka,在跟着视频进行编码的时候,遇到了eureka的一些问题
问题一:
@EnableEurekaServer无法正确的被引入
查阅了百度的一些资料,主要说明是springboot与spingcloud的版本不一致,使用Finchley.RELEASE版本即可。
修改了此处,发现@EnableEurekaServer仍然没有被引入,了解到导致不能正确的进行版本引入的时候,多是配置的问题,所以我重新查看了一下pom.xml文件
子pom.xml
父pom.xml
少了刚刚创建的eureka的项目
补充一下,修改后的配置为:
子pom.xml
父pom.xml文件
在子pom.xml文件中正确的配置eureka
<dependencies>
<!--启动需要-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
</dependencies>
此时可以正确的进行@EnableEurekaServer的引入了
进行部署的时候,遇到了第二个问题:java.lang.AbstractMethodError: null
从百度上查看,仍然是版本不匹配的问题,此时需要将父pom.xml文件中的配置修改为2.1.1RELEASE
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
重新部署后,发现了第三个问题:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'eurekaRegistration', defined in class path resource
[org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$EurekaClientConfigu
ration.class], could not be registered. A bean with that name has already been defined in
class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaC
lientConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow
-bean-definition-overriding=true
百度过程中找到一篇博文
https://blog.csdn.net/yjt520557/article/details/91408635
就是将
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
修改为
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
重新启动部署,成功