spring cloud问题总结

【1】默认生成的pom.xml文件,junit依赖jar没有配置版本,父工程pom文件加上 <version>2.1.4.RELEASEversion>,解决spring boot启动类编译错误问题

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-testartifactId>
    <version>2.1.4.RELEASEversion>
    <scope>testscope>
dependency>

【2】启动类(@SpringBootApplication注解的类)要放在顶级父目录,如下图

spring cloud问题总结_第1张图片

所有的controller类都要放在com.szh包或者其子包下面,否则访问controller的时候会报white page错误

【3】启动eureka失败,console日志如下:

2019-04-09 15:49:02.301 ERROR 10856 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    java.lang.invoke.MethodHandleNatives.resolve(Native Method)

The following method did not exist:

    com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;

The method's class, com.google.gson.GsonBuilder, is available from the following locations:

    jar:file:/D:/Program%20Files/apache-maven-3.2.3/mvn_repository/com/google/code/gson/gson/2.1/gson-2.1.jar!/com/google/gson/GsonBuilder.class

It was loaded from the following location:

    file:/D:/Program%20Files/apache-maven-3.2.3/mvn_repository/com/google/code/gson/gson/2.1/gson-2.1.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.gson.GsonBuilder

问题原因:

gson 的jar版本不对,在“Extenal Libraries”下面找到gson包,修改jar版本,步骤如下:

1)点开"Extenal Libraries"

spring cloud问题总结_第2张图片

2)找到gson字样的jar包,右键单击

spring cloud问题总结_第3张图片

3)直接选择当前maven库中的最高版本

spring cloud问题总结_第4张图片

4)清理maven工程,重新启动spring boot,问题解决

转载于:https://my.oschina.net/u/3874846/blog/3034133

你可能感兴趣的:(spring cloud问题总结)