【1】默认生成的pom.xml文件,junit依赖jar没有配置版本,父工程pom文件加上 <version>2.1.4.RELEASE</version>,解决spring boot启动类编译错误问题
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.1.4.RELEASE</version> <scope>test</scope> </dependency>
【2】启动类(@SpringBootApplication注解的类)要放在顶级父目录,如下图
所有的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"
2)找到gson字样的jar包,右键单击
3)直接选择当前maven库中的最高版本
4)清理maven工程,重新启动spring boot,问题解决