启动以后,后台报错:
java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:558) ~[jackson-databind-2.8.8.jar:2.8.8]
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:474) ~[jackson-databind-2.8.8.jar:2.8.8]
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:588) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:57) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:61) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:159) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:188) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getSecureRestTemplate(ConfigServicePropertySourceLocator.java:195) ~[spring-cloud-config-client-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:78) ~[spring-cloud-config-client-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:93) ~[spring-cloud-context-1.2.3.RELEASE.jar:1.2.3.RELEASE]
我以为是没有引入包,但是,引入了又报 spring core的包找不到……
最后发现,是maven的配置文件 spring-cloud-starter-eureka 和 spring-cloud-starter-config写反了。
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
这个文件是要报错的。 config应该写前面eureka 应该写后面。 写好顺序就解决了。不然要报莫名其妙的找不到类的错误。