Eureka Server 在 Spring Boot 中启动时出现错误

Posted

技术标签:

【中文标题】Eureka Server 在 Spring Boot 中启动时出现错误【英文标题】:Eureka Server while starting in spring boot getting the errors 【发布时间】:2020-02-27 04:20:35 【问题描述】:

启动 Eureka Server 时无法开始获取错误

尝试更改云版本更改版本

<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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>eurekaserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eurekaserver</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    </properties>

依赖部分


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</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>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.RC1</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/mileston</url>
        </repository>
    </repositories>

</project>

日志:

2019-11-01 00:05:18.833  INFO 7544 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$3b9dbe3e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-11-01 00:05:19.455  INFO 7544 --- [           main] c.e.e.EurekaserverApplication            : No active profile set, falling back to default profiles: default

2019-11-01 00:05:20.771 WARN 7544 --- [main] o.s.boot.actuate.endpoint.EndpointId:端点 ID 'service-registry' 包含无效字符,请迁移到有效格式。 2019-11-01 00:05:21.119 INFO 7544 --- [main] os.cloud.context.scope.GenericScope:BeanFactory id=9f8a0e73-0f18-37e3-a449-5d163b119105 2019-11-01 00:05:21.158 错误 7544 --- [main] os.boot.SpringApplication:应用程序运行失败 java.lang.NoClassDefFoundError: org/apache/commons/lang/text/StrLookup 在 java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na] 在 java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137) ~[na:na] 在 java.base/java.lang.Class.getDeclaredConstructors(Class.java:2357) ~[na:na] 在 org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.findBindConstructor(ConfigurationPropertiesBean.java:318) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forClass(ConfigurationPropertiesBean.java:300) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:57) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 com.example.eurekaserver.EurekaserverApplication.main(EurekaserverApplication.java:12) ~[classes/:na] 引起:java.lang.ClassNotFoundException:org.apache.commons.lang.text.StrLookup 在 java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na] 在 java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na] 在 java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na] ...省略了18个常用框架

【问题讨论】:

运行 mvn clean install 并再次测试。 在 mvn clean install 后仍然出现同样的错误 然后检查那个appache类是否出现在你的类路径中。 【参考方案1】:

这段代码可能对你有帮助,我在我的 pom 文件中使用了代码,你也可以像这样查看和修复你的代码。

    <?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.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.sencerseven.microservices</groupId>
    <artifactId>netflix-eureka-naming-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>netflix-eureka-naming-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <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>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </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>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

而且你必须把@EnableEurekaServer注解放到mainclass上

【讨论】:

仍然出现同样的错误原因:java.lang.ClassNotFoundException: org.apache.commons.lang.text.StrLookup at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8 .0_221] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_221] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_221] at java.lang。 ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_221] ...省略了18个常用框架

以上是关于Eureka Server 在 Spring Boot 中启动时出现错误的主要内容,如果未能解决你的问题,请参考以下文章

没有 Spring-boot 的 Eureka 服务发现

spring cloud 注册与发现Eureka

spring boot eureka server

spring boot 1.5.2中eureka客户端如何找到eureka server?

Eureka Server 在 Spring Boot 中启动时出现错误

Spring WebClient 和 Eureka Server