Eureka集成过程常见异常

异常1:jar包冲突类冲突ServletContext.class

An attempt was made to call the method javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations: 尝试调用方法javax.servlet.ServletContext.getVirtualServerName();但它并不存在。

它的类,javax.servlet。ServletContext,可从以下位置获得: jar:file:/E:/Software/apache-maven-3.5.3/repository/org/mortbay/jetty/servlet-api-2.5/6.1.14/servlet-api-2.5-6.1.14.jar!/javax/servlet/ServletContext.class jar:file:/E:/Software/apache-maven-3.5.3/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/E:/Software/apache-maven-3.5.3/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.39/tomcat-embed-core-8.5.39.jar!/javax/servlet/ServletContext.class It was loaded from the following location:

它是从以下地点加载的: file:/E:/Software/apache-maven-3.5.3/repository/org/mortbay/jetty/servlet-api-2.5/6.1.14/servlet-api-2.5-6.1.14.jar Action: Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext

原因:从错误信息看出,在tomcat-embed-core-9.0.17.jar和servlet-api-2.5.jar里面都有javax.servlet.ServletContext, 而这个类在eureka中使用默认用了servlet-api-2.5.jar进行。经过查看发现,servlet-api-2.5.jar是eureka里面引进来的

解决:

方法1(不推荐)

Project Structure----Modules—微服务----Dependences

重复依赖仅保留一个其余改为Test或删除,删除或者改为test

方法2

添加:
<exclusion>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-quartz</artifactId>
</exclusion>
例如:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    <version>2.1.3.RELEASE</version>
    <exclusions>
        <exclusion>                
            <artifactId>servlet-api</artifactId>                
            <groupId>javax.servlet</groupId>       
        </exclusion>
    </exclusions>
</dependency>

最好的办法是添加依赖版本时就排除冲突问题

异常2:找不到ConfigurationPropertiesBean

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘bootstrapImportSelectorConfiguration’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationPropertiesBean at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)

java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationPropertiesBean

at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]

​ at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]

​ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_151]

​ at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]

原因:springboot版本 与 springcloud的版本 两者不匹配报错

解决:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.11.RELEASE</version>                          -----springboot版本
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR4</spring-cloud.version>    ----springcloud版本
    </properties>

修改后重启IDEA;

异常3:Compilation failed:internal java compiler error

Compilation failed:internal java compiler error

解决:

建议在pom文件中定义properties

	<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
    </properties>

或者

1、项目名称处右击,点击"Open Moudle Settings".

2、点击左边列表“Project”,右边Project SDK选择1.8,Project language level选择“8 - Lambda, type annotations etc."

3、点击左边列表“Moudles,右边Source下的Language level选择“8 - Lambda, type annotations etc.",保存设置点击“OK”

4、点击左上角“IntelliJ IDEA", 点击Preference, 点击“Build, Execution, Deployment"下的“Java Compiler”

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xnL9gIrs-1616063949066)(D:\0.0.0.0aaaaaaaa资料\Images重要\compile.png)]

异常4:Error creating bean with name org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration

原因:新版本的Spring Cloud对熔断器Hystrix有要求,Eureka中必须添加对Hystrix的依赖才可以

解决:

eureka依赖改为

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

或者

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

异常5:No goals have been specified for this build

No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process- classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.

解决:

在pom.xml文件中的标签之间添加compile即可

	<build>
        <defaultGoal>compile</defaultGoal>
    </build>

异常6:Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform depend

Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

解决:

在项目pom.xml中增加如下配置:

<properties>
    <!--编译编码-->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

异常7:Spring boot java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver

原因1:引用了ali的druid连接池,

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.10</version>
</dependency>

druid默认的spring.boot 版本是1.5.12,这个版本中引入了RelaxedPropertyResolver,如果是springboot2.X中就会找不到,所以报错。因此在需要pom.xml文件中,引入 下面依赖覆盖掉druid-spring-boot-starter中的spring.boot版本 。

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.0.3.RELEASE</version>
</parent>

或者

springcloud项目中:

	<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-autoconfigure</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

异常8:org.springframework.jdbc.datasource.embedded.EmbeddedData

原因:是缺少jdbc相关的jar包,

解决办法:引入spring-jdbc 包

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
</dependency>

.springframework.jdbc.datasource.embedded.EmbeddedData

原因:是缺少jdbc相关的jar包,

解决办法:引入spring-jdbc 包

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
</dependency>

版权声明:本文为qq_45445841原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。