相关系列文章

Spring boot升级到2.3.2.Release和Spring framework升级到5.28.Release踩过的坑_keeppractice的博客-CSDN博客

Hibernate升级到5.4.18.final的过程踩过的坑_keeppractice的博客-CSDN博客

Spring boot admin 升级到2.3.1 遇到的问题总结_keeppractice的博客-CSDN博客

目录

1  java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata

2.不能解决 spring-cloud-starter-netflix-hystrix, spring-cloud-starter-netflix-hystrix-dashboard,spring-cloud-starter-netflix-zuul.

3. 编译问题:ClientFilter和HTTPBasicAuthFilter类找不到了。

4. feign.hystrix.FallbackFactory类找不到了

5. java.lang.NoSuchMethodError: org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties.getServlet()Lorg/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties$Servlet;

6.  org.mockito.Matchers 编译错误,这个类不见了

7. spring-data-rest-hal-browser依赖包不能解决,不见了

8. The dependencies of some of the beans in the application context form a cycle

9. The following method did not exist: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

10 Keystore was tampered with, or password was incorrect

11. java.lang.IllegalStateException: couldn't determine local port. Please set spring.boot.admin.client.instance.service-base-url

12. java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy

13. java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/AnnotationIntrospector$XmlExtensions

14. java.lang.NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath()Ljava/lang/String;

15. Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: xxxx

16. Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.

17. java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(Ljava/lang/String;Lorg/springframework/cloud/client/loadbalancer/Request;)Lorg/springframework/cloud/client/ServiceInstance;

18 Keystore was tampered with, or password was incorrect

19. Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy 

20. eclipse debug启动老是跳转到断点,提示SilentExitException

21. Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.dataformat.xml.XmlMapper

22. Spring Boot [xxxxx] is not compatible with this Spring Cloud release train

23. Eureka datacenter and environment not displayed on the Eureka dashboard

24. /actuator/info Endpoint 节点显示不出来信息了 

其它相关知识


版本

LibraryCurrentUpgraded
Spring-boot2.3.22.6.2 
Spring cloudHoxton.SR82021.0.0 
Spring5.2.8.RELEASE5.3.14
hibernate5.4.18.Final5.4.33.Final
Spring admin2.3.12.4.1

1  java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata

错误信息:

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_51]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_51]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_51]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:417) ~[spring-orm-5.3.14.jar:5.3.14]
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:388) ~[spring-orm-5.3.14.jar:5.3.14]
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:335) ~[spring-orm-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.3.14.jar:5.3.14]
	... 30 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_51]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_51]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[?:1.8.0_51]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_51]
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_51]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_51]

错误原因:

Spring cloud用的是老版本Hoxton.SR8

Spring Cloudhttps://spring.io/projects/spring-cloud

Release Train

Boot Version

2021.0.x aka Jubilee

2.6.x

2020.0.x aka Ilford

2.4.x, 2.5.x (Starting with 2020.0.3)

Hoxton

2.2.x, 2.3.x (Starting with SR5)

Greenwich

2.1.x

Finchley

2.0.x

Edgware

1.5.x

Dalston

1.5.x

Table 1. Release train Spring Boot compatibility

解决方法:

升级spring cloud ->2021.0.0 版本

2.不能解决 spring-cloud-starter-netflix-hystrix, spring-cloud-starter-netflix-hystrix-dashboard,spring-cloud-starter-netflix-zuul.

原因:

spring cloud 在2020.0版本的时候已经移掉了除了Eureka以外的所有其它的Netfix的组件比如ribbon, Hystrix,Zuul.. 等等

可以查看spring-cloud-netflix-dependencies这里的依赖。

解决方法:

加特定的版本,比如加2.2.6.RELEASE

 	<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
			<version>2.2.6.RELEASE</version>
	</dependency>

    <dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
			 <version>2.2.6.RELEASE</version>
		</dependency>	
	<dependency>
    		<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
			<version>2.2.6.RELEASE</version>
	</dependency>

或者根据官方给出的替换方案,替换掉Netflix的组件

Spring Cloud Greenwich.RC1 available now

3. 编译问题:ClientFilter和HTTPBasicAuthFilter类找不到了。

import com.sun.jersey.api.client.filter.ClientFilter;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

原因待查;

可以看到Jersey-client的scope类型是runtime.

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.netflix.ribbon</groupId>
  <artifactId>ribbon-httpclient</artifactId>
  <version>2.3.0</version>
  <dependencies>
....
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <version>1.19.1</version>
      <scope>runtime</scope>
    </dependency>
....

解决方法:加一下面的依赖

        <dependency>
              <groupId>com.sun.jersey</groupId>
              <artifactId>jersey-client</artifactId>
              <version>1.19.1</version>
        </dependency>

4. feign.hystrix.FallbackFactory类找不到了

原因:

Hystrix-feign.jar 被spring-cloud-openFeign-core替换了。

解决方法:换成下面这个包

import org.springframework.cloud.openfeign.FallbackFactory;

5. java.lang.NoSuchMethodError: org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties.getServlet()Lorg/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties$Servlet;

错误信息:

[2022-02-11 09:02:05.325][][]@[] ERROR[registrationTask1](org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler:95) - Unexpected error occurred in scheduled task
java.lang.NoSuchMethodError: org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties.getServlet()Lorg/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties$Servlet;
	at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getManagementContextPath(ServletApplicationFactory.java:86) ~[spring-boot-admin-client-2.3.1.jar:2.3.1]
	at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getManagementBaseUrl(ServletApplicationFactory.java:77) ~[spring-boot-admin-client-2.3.1.jar:2.3.1]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getHealthUrl(DefaultApplicationFactory.java:154) ~[spring-boot-admin-client-2.3.1.jar:2.3.1]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.createApplication(DefaultApplicationFactory.java:80) ~[spring-boot-admin-client-2.3.1.jar:2.3.1]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationRegistrator.register(DefaultApplicationRegistrator.java:56) ~[spring-boot-admin-client-2.3.1.jar:2.3.1]
	at de.codecentric.boot.admin.client.registration.RegistrationApplicationListener$$Lambda$1147/853202089.run(Unknown Source) ~[?:?]
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.14.jar:5.3.14]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_51]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[?:1.8.0_51]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[?:1.8.0_51]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[?:1.8.0_51]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[?:1.8.0_51]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[?:1.8.0_51]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51]

原因:升级springboot到2.6.2版本后,ManagementServerProperties类改了。已经没有.getServlet().getContextPath()方法了。

在2.3.1版本的spring admin里getManagementContextPath方法如下:

package de.codecentric.boot.admin.client.registration

public class ServletApplicationFactory extends DefaultApplicationFactory {

    protected String getManagementContextPath() {
        return management.getServlet().getContextPath();
    }

在2.4.1版本的spring admin里getManagementContextPath方法如下:

public class ServletApplicationFactory extends DefaultApplicationFactory {

    protected String getManagementContextPath() {
        return management.getBasePath();
    }

解决方法:

升级spring admin 到2.4.1版本

6.  org.mockito.Matchers 编译错误,这个类不见了

原因:

Use org.mockito.ArgumentMatchers. This class is now deprecated in order to avoid a name clash with Hamcrest * org.hamcrest.Matchers class. This class will likely be removed in version 3.0.

解决方法:

org.mockito.ArgumentMatchers 用这个类。

其它:

Matchers.anyObject()   替换方案是:ArgumentMatchers.any()

Matchers.anyListOf(String.class) 替换方案是: ArgumentMatchers.anyList()        

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

上面的编译问题,加junit依赖

    	<dependency>
		    <groupId>junit</groupId>
		    <artifactId>junit</artifactId>
		    <scope>test</scope>
		</dependency>

7. spring-data-rest-hal-browser依赖包不能解决,不见了

相关代码

        <dependency>
            <groupId>org.springframework.data</groupId>
           <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency>

解决方法

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-explorer</artifactId>
        </dependency>

8. The dependencies of some of the beans in the application context form a cycle

 
Description:
 
The dependencies of some of the beans in the application context form a cycle:
 
   userController (field private xxx.user.service.userWorkflowService xxx.user.controller.userController.userService)
      ↓
   userProcessorConfig
      ↓
   xxx.core.workflow.TestWorkflowConfiguration#0 (field private xxx.Test.service.TestDataService xxx.core.workflow.TestWorkflowConfiguration.pendingTestDataService)
┌─────┐
|  xxx.Test.TestConfiguration#0
↑     ↓
|  xxx.Test.util.ATestRuleConfiguration#0 (field private xxx.Test.TestConfiguration xxx.Test.util.ATestRuleConfiguration.TestConfiguration)
└─────┘
 
 
Action:
 
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

解决方法:

spring.main.allow-circular-references=true

9. The following method did not exist: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;


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

    org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1318)

The following method did not exist:

    javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

The calling method's class, org.apache.catalina.authenticator.AuthenticatorBase, was loaded from the following location:

    jar:file::**/WEB-INF/lib/tomcat-embed-core-9.0.56.jar!/org/apache/catalina/authenticator/AuthenticatorBase.class

The called method's class, javax.servlet.ServletContext, is available from the following locations:

    jar:file:***/WEB-INF/lib/servlet-api-2.5.jar!/javax/servlet/ServletContext.class
    jar:file::**/tomcat-embed-core-9.0.56.jar!/javax/servlet/ServletContext.class

The called method's class hierarchy was loaded from the following locations:

    javax.servlet.ServletContext: jar:file::**/WEB-INF/lib/servlet-api-2.5.jar!/


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.apache.catalina.authenticator.AuthenticatorBase and javax.servlet.ServletContext

原因:

我引进了servlet-api.2.5 版本

但是ServletContext.getVirtualServerName() 方法只有在3.1后才有。

public interface ServletContext {
。。。。
    /**
     * Get the primary name of the virtual host on which this context is
     * deployed. The name may or may not be a valid host name.
     *
     * @return The primary name of the virtual host on which this context is
     *         deployed
     * @since Servlet 3.1
     */
    public String getVirtualServerName();

解决方法:

<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
			<exclusions>
				<exclusion>
					 <groupId>javax.servlet</groupId>
     				 <artifactId>servlet-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

10 Keystore was tampered with, or password was incorrect

错误信息

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2022-02-14 10:51:06.847][][]@[] ERROR[main](org.springframework.boot.SpringApplication:819) - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.14.jar!/:5.3.14]
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.14.jar!/:5.3.14]
Caused by: org.springframeworkboot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.6.2.jar!/:2.6.2]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.6.2.jar!/:2.6.2]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.14.jar!/:5.3.14]
        ... 20 more
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.6.2.jar!/:2.6.2]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.6.2.jar!/:2.6.2]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.6.2.jar!/:2.6.2]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.14.jar!/:5.3.14]
        ... 20 more
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1075) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.56.jar!/:?]
        ... 20 more

Caused by: java.lang.IllegalArgumentException: Keystore was tampered with, or password was incorrect
        at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:99) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:71) ~[tomcat-embed-core-9.0.56.jar!/:?]

        ... 20 more
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
        at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:882) ~[sunjce_provider.jar:1.8.0_311]
        at java.security.KeyStore.load(KeyStore.java:1445) ~[?:1.8.0_311]
        at org.apache.tomcat.util.security.KeyStoreUtil.load(KeyStoreUtil.java:69) ~[tomcat-embed-core-9.0.56.jar!/:?]
        a
        ... 20 more
Caused by: java.security.UnrecoverableKeyException: Password verification failed
        at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:882) ~[sunjce_provider.jar:1.8.0_311]
        at java.security.KeyStore.load(KeyStore.java:1445) ~[?:1.8.0_311]
        at org.apache.tomcat.util.security.KeyStoreUtil.load(KeyStoreUtil.java:69) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:215) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:207) ~[tomcat-embed-core-9.0.56.jar!/:?]
        at org.apache.tomcat.util.net.SSLUtilBase.getKeyManagers(SSLUtilBase.java:281) ~[tomcat-embed-core-9.0.56.jar!/:?]

解决方法

设置下面参数:

server.ssl.key-store-password= ***

参考资料:https://github.com/spring-projects/spring-boot/issues/24256

11. java.lang.IllegalStateException: couldn't determine local port. Please set spring.boot.admin.client.instance.service-base-url

解决方法:

设置下面参数,因为tomcat不知道port号

spring.boot.admin.client.instance.serviceBaseUrl=http://localhost:8080 (application url)

参考资料

couldn't determine local port. Please supply service-base-url. · Issue #796 · codecentric/spring-boot-admin · GitHub

12. java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy

错误信息:

Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365) ~[catalina.jar:9.0.36.redhat-8]
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) ~[catalina.jar:9.0.36.redhat-8]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.lambda$applyNamingStrategies$1(HibernateProperties.java:178) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.lambda$applyNamingStrategy$2(HibernateProperties.java:187) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at java.util.HashMap.computeIfAbsent(HashMap.java:1129) ~[?:1.8.0_311]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.applyNamingStrategy(HibernateProperties.java:187) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.applyNamingStrategies(HibernateProperties.java:177) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.access$000(HibernateProperties.java:146) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:102) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:95) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_311]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_311]

原因是:

org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy

这个类是hibenrate.5.5 新引进的类。但是我们用的hibernate.5.3.x

Hibernate ORM 5.5.4.Final released - In Relation To

解决方法:

加下面系统参数

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

参考资料

https://www.baeldung.com/hibernate-field-naming-spring-boot

13. java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/AnnotationIntrospector$XmlExtensions

错误信息:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/AnnotationIntrospector$XmlExtensions
        at com.fasterxml.jackson.dataformat.xml.util.AnnotationUtil.findNamespaceAnnotation(AnnotationUtil.java:19) ~[jackson-dataformat-xml-2.11.1.jar:2.11.1]
        at com.fasterxml.jackson.dataformat.xml.ser.XmlBeanSerializerModifier.changeProperties(XmlBeanSerializerModifier.java:44) ~[jackson-dataformat-xml-2.11.1.jar:2.11.1]
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanOrAddOnSerializer(BeanSerializerFactory.java:397) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanOrAddOnSerializer(BeanSerializerFactory.java:286) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:231) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:165) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1388) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1336) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.SerializerProvider._findExplicitUntypedSerializer(SerializerProvider.java:1305) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.hasSerializerFor(DefaultSerializerProvider.java:260) ~[jackson-databind-2.10.1.jar:2.10.1]
        at com.fasterxml.jackson.databind.ObjectMapper.canSerialize(ObjectMapper.java:3007) ~[jackson-databind-2.10.1.jar:2.10.1]
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canWrite(AbstractJackson2HttpMessageConverter.java:274) ~[spring-web-5.3.14.jar:5.3.14]
        at org.springframework.http.converter.AbstractGenericHttpMessageConverter.canWrite(AbstractGenericHttpMessageConverter.java:76) ~[spring-web-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.getProducibleMediaTypes(AbstractMessageConverterMethodProcessor.java:380) ~[spring-webmvc-5.3.14.jar:5.3.14]

解决方法:有两个解决方法

1. 升级Jackson相关的jar 到2.13.0

pom.xml

<jackson-bom.version>2.13.1</jackson-bom.version>

或升级

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.13.0</version>
      </dependency>

2. 降级Jackson相关的jar到2.11.1

pom.xml

<jackson-bom.version>2.11.1</jackson-bom.version>

参考资料:

Jackson Release 2.13 · FasterXML/jackson Wiki · GitHub

14. java.lang.NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath()Ljava/lang/String;

Caused by: java.lang.NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath()Ljava/lang/String;
        at org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping.lookupHandler(ZuulHandlerMapping.java:87) ~[spring-cloud-netflix-zuul-2.2.6.RELEASE.jar:2.2.6.RELEASE]
        at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal(AbstractUrlHandlerMapping.java:152) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:498) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1261) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1043) ~[spring-webmvc-5.3.14.jar:5.3.14]
        ... 71 more

解决方法

https://www.jianshu.com/p/94353ee0707b

https://stackoverflow.com/questions/68100671/nosuchmethoderror-org-springframework-boot-web-servlet-error-errorcontroller-ge

15. Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: xxxx

错误信息:

com.netflix.zuul.exception.ZuulException: Forwarding error
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:198) ~[spring-cloud-netflix-zuul-2.2.6.RELEASE.jar:2.2.6.RELEASE]
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:173) ~[spring-cloud-netflix-zuul-2.2.6.RELEASE.jar:2.2.6.RELEASE]
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:119) ~[spring-cloud-netflix-zuul-2.2.6.RELEASE.jar:2.2.6.RELEASE]
        at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:118) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116) ~[zuul-core-1.3.1.jar:1.3.1]
        at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81) ~[zuul-core-1.3.1.jar:1.3.1]
....
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: xxxx
        at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber$1.call(OperatorRetryWithPredicate.java:127) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(TrampolineScheduler.java:73) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(TrampolineScheduler.java:52) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:79) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:45) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Subscriber.setProducer(Subscriber.java:209) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]

解决方法:

1. 加下面标注

@RibbonClients(defaultConfiguration = RibbonEurekaClientConfig.class)

2. 创建下面配置类

 
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Bean;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AvailabilityFilteringRule;
import com.netflix.loadbalancer.DummyPing;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
 
public class RibbonEurekaClientConfig {
    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new DummyPing();
    }
    @Bean
    public IRule ribbonRule(IClientConfig config) {
        return new AvailabilityFilteringRule();
    }
    @Autowired
    DiscoveryClient discoveryClient;
    @Bean
    public ServerList<Server> getServerList(IClientConfig config) {
 
        return new ServerList<Server>() {
            @Override
            public List<Server> getInitialListOfServers() {
                return new ArrayList<>();
            }
 
            @Override
            public List<Server> getUpdatedListOfServers() {
                List<Server> serverList = new ArrayList<>();
 
                List<ServiceInstance> list = discoveryClient.getInstances(config.getClientName());
                for (ServiceInstance instance : list) {
                    serverList.add(new Server(instance.getHost(), instance.getPort()));
                }
                return serverList;
            }
        };
    }
}

参考资料

microservices - Zuul Forwarding error, Load balancer does not have available server for client - Stack Overflow

具体原因可看

https://blog.csdn.net/keeppractice/article/details/122966391

16. Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.

异常信息

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.18.jar!/:5.3.18]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.18.jar!/:5.3.18]
        ... 25 more
Caused by: java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
        at org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler.setServletContext(DefaultServletHttpRequestHandler.java:111) ~[spring-webmvc-5.3.18.jar!/:5.3.18]
        at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.enable(DefaultServletHandlerConfigurer.java:85) ~[spring-webmvc-5.3.18.jar!/:5.3.18]
        at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.enable(DefaultServletHandlerConfigurer.java:71) ~[spring-webmvc-5.3.18.jar!/:5.3.18]
        at com.citi.icg.as.server.rest.RestfulServiceConfiguration.configureDefaultServletHandling(RestfulServiceConfiguration.java:53) ~[aspen-common-SPRING-2.6.2-SNAPSHOT.jar!/:SPRING-2.6.2-SNAPSHOT]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:644) ~[spring-webmvc-5.3.18.jar!/:5.3.18]
        at com.citi.icg.as.server.rest.RestfulServiceConfiguration$$EnhancerBySpringCGLIB$$53da7798.CGLIB$defaultServletHandlerMapping$26(<generated>) ~[aspen-common-SPRING-2.6.2-SNAPSHOT.jar!/:SPRING-2.6.2-SNAPSHOT]

解决方法

加下面参数

server.servlet.register-default-servlet=true

或者

@Bean
WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> enableDefaultServlet() {
    return (factory) -> factory.setRegisterDefaultServlet(true);
}

参考资料

java - IllegalStateException after upgrading web app to Spring Boot 2.4 - Stack Overflow

17. java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(Ljava/lang/String;Lorg/springframework/cloud/client/loadbalancer/Request;)Lorg/springframework/cloud/client/ServiceInstance;

错误信息

Caused by: java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(Ljava/lang/String;Lorg/springframework/cloud/client/loadbalancer/Request;)Lorg/springframework/cloud/client/ServiceInstance;
        at org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient.execute(FeignBlockingLoadBalancerClient.java:97) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:119) ~[feign-core-11.7.jar:?]
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89) ~[feign-core-11.7.jar:?]
        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-11.7.jar:?]
        at com.sun.proxy.$Proxy1210.fetchAllEventTypes(Unknown Source) ~[?:?]
        at com.citi.icg.as.common.staticData.service.StaticDataServiceImpl.getAllEventTypes(StaticDataServiceImpl.java:46) ~[classes/:SPRING-2.3.2-SNAPSHOT]
        at com.citi.icg.as.common.staticData.controller.StaticDataController.getAllEventTypes(StaticDataController.java:45) ~[classes/:SPRING-2.3.2-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_311]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_311]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_311]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_311]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.14.jar:5.3.14]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.14.jar:5.3.14]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.14.jar:5.3.14]
        ... 71 more

原因:

OpenFeign依赖spring-cloud-starter-loadbalancer做负载均衡,之前是用Ribbon的。如果加了spring-cloud-starter-netflix-zuul后,zuul依赖了Ribbon做负载均衡。

LoadBalancerClient 有两个RibbonLoadBalancerClient和BlockingLoadBalancerClient类。结果OpenFeigin用RibbonLoadBalancerClient使用报错。

如果单用OpenFeign是不会有这个问题的。

相关代码

OpenFeigin 用BlockingLoadBalancerClient, 但是Zuul用RibbonLoadBalancerClient。 但是这两类继承同一个类LoadBalancerClient而且只能实例化一个。

public class BlockingLoadBalancerClientAutoConfiguration {
 
	@Bean
	@ConditionalOnBean(LoadBalancerClientFactory.class)
	@ConditionalOnMissingBean
	public LoadBalancerClient blockingLoadBalancerClient(LoadBalancerClientFactory loadBalancerClientFactory) {
		return new BlockingLoadBalancerClient(loadBalancerClientFactory);
	}
public class RibbonAutoConfiguration {
 
...
	@Bean
	@ConditionalOnMissingBean(LoadBalancerClient.class)
	public LoadBalancerClient loadBalancerClient() {
		return new RibbonLoadBalancerClient(springClientFactory());
	}

解决方法:

	@Bean
	public LoadBalancerClient blockingLoadBalancerClient(LoadBalancerClientFactory loadBalancerClientFactory) {
		return new BlockingLoadBalancerClient(loadBalancerClientFactory);
	}

18 Keystore was tampered with, or password was incorrect

Caused by: java.lang.IllegalArgumentException: Keystore was tampered with, or password was incorrect
	at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:99) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:71) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:234) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1072) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.6.6.jar:2.6.6]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.18.jar:5.3.18]
	... 13 more
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
	at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:772) ~[?:1.8.0_51]
	at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55) ~[?:1.8.0_51]
	at java.security.KeyStore.load(KeyStore.java:1445) ~[?:1.8.0_51]

相关代码:

package org.apache.tomcat.util.net;
.....
public abstract class SSLUtilBase implements SSLUtil {
......          
      char[] storePass = null;
                if (pass != null && (!"".equals(pass) ||
                        "JKS".equalsIgnoreCase(type) || "PKCS12".equalsIgnoreCase(type))) {
                    storePass = pass.toCharArray();
                }
                KeyStoreUtil.load(ks, istream, storePass);

如果没有设置key store的值的话,storePass 返回值是一个默认值changeit。

有没有设置值,可以在Ssl类里的现有方法里设置断点,debug的时候就可以知道了。

package org.springframework.boot.web.server;
public class Ssl {
...
	
/**
	 * Return the password used to access the key in the key store.
	 * @return the key password
	 */
	public String getKeyPassword() {
		return this.keyPassword;
	}

	public void setKeyPassword(String keyPassword) {
		this.keyPassword = keyPassword;
	}

	/**
	 * Return the path to the key store that holds the SSL certificate (typically a jks
	 * file).
	 * @return the path to the key store
	 */
	public String getKeyStore() {
		return this.keyStore;
	}

	public void setKeyStore(String keyStore) {
		this.keyStore = keyStore;
	}

	/**
	 * Return the password used to access the key store.
	 * @return the key store password
	 */
	public String getKeyStorePassword() {
		return this.keyStorePassword;
	}

	public void setKeyStorePassword(String keyStorePassword) {
		this.keyStorePassword = keyStorePassword;
	}

解决方法:  

设置下面系统变量,我们系统是没有设置第一个。

 System.setProperty("server.ssl.key-store-password", keyPassword); 
 System.setProperty("server.ssl.key-password", keyPassword);
 System.setProperty("server.ssl.trust-store-password", keyPassword);

19. Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy 

错误信息:

ernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.18.jar!/:5.3.18]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.18.jar!/:5.3.18]
        ... 25 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.lambda$applyNamingStrategies$1(HibernateProperties.java:178) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.lambda$applyNamingStrategy$2(HibernateProperties.java:187) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at java.util.HashMap.computeIfAbsent(HashMap.java:1129) ~[?:1.8.0_311]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.applyNamingStrategy(HibernateProperties.java:187) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.applyNamingStrategies(HibernateProperties.java:177) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties$Naming.access$000(HibernateProperties.java:146) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:102) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:95) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:132) ~[spring-boot-autoconfigure-2.6.6.jar!/:2.6.6]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_311]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_311]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_311]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_311]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.18.jar!/:5.3.18]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.18.jar!/:5.3.18]
        ... 25 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy 
 

相关信息:

项目中用了JPA. 只定义了Datasource , JPA 的具体实现用了Hibernate.

解决方法:

在application.properties 加下面系统变量。

spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

20. eclipse debug启动老是跳转到断点,提示SilentExitException

两个解决方法:

第一个:

出现这种状况是因为Eclipse默认开启挂起未捕获的异常(Suspend execution on uncaught exceptions),只要关闭此项就可以了。

在eclipse中选择Window->Preference-> Java ->Debug,将“Suspend execution on uncaught exceptions”的勾去掉即可。


第二个: 加下系统参数

 -Dspring.devtools.restart.enabled=false

但是这样如果有异常的时候,就没有异常抛出了。所以在加一个try catch语句

public static void main(String[] args) {
		try {
			SpringApplication app = new SpringApplication(App.class);
			app.run(args);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

21. Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.dataformat.xml.XmlMapper

具体异常信息

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.dataformat.xml.XmlMapper
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder$XmlObjectMapperInitializer.create(Jackson2ObjectMapperBuilder.java:911) ~[spring-web-5.3.18.jar!/:5.3.18]
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:669) ~[spring-web-5.3.18.jar!/:5.3.18]
        at org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter.<init>(MappingJackson2XmlHttpMessageConverter.java:52) ~[spring-web-5.3.18.jar!/:5.3.18]

原因是

jackson.databind.version 的版本和jackson-dataformat-xml-version不一致

        <jackson.databind.version>2.11.2</jackson.databind.version>
        <jackson-dataformat-xml-version>2.13.2</jackson-dataformat-xml-version>

解决方法:

保持一致就可以了

        <jackson.databind.version>2.13.2</jackson.databind.version>
        <jackson-dataformat-xml-version>2.13.2</jackson-dataformat-xml-version>

22. Spring Boot [xxxxx] is not compatible with this Spring Cloud release train

错误信息

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

Description:

Your project setup is incompatible with our requirements due to following reasons:

- Spring Boot [xxxxx] is not compatible with this Spring Cloud release train


Action:

Consider applying the following actions:

- Change Spring Boot version to one of the following versions [2.6.x, 2.7.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn]. 
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]

相关代码

org.springframework.boot.SpringBootVersion

private static String determineSpringBootVersion() {
		String implementationVersion = SpringBootVersion.class.getPackage().getImplementationVersion();
		if (implementationVersion != null) {
			return implementationVersion;
		}
		CodeSource codeSource = SpringBootVersion.class.getProtectionDomain().getCodeSource();
		if (codeSource == null) {
			return null;
		}
		URL codeSourceLocation = codeSource.getLocation();
		try {
			URLConnection connection = codeSourceLocation.openConnection();
			if (connection instanceof JarURLConnection) {
				return getImplementationVersion(((JarURLConnection) connection).getJarFile());
			}
			try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
				return getImplementationVersion(jarFile);
			}
		}
		catch (Exception ex) {
			return null;
		}
	}

原因:

有的项目里用下面Maven插件打包fat jar,打包出来的Jar里把所有的依赖jar包都打包成了class文件,所以这些依赖的Jar中META-INF/MANIFEST.MF文件就丢了。这个文件是SpringBootVersion这个类取版本号用的。 这样springboot的版本号就取做了,最终导致这个问题。

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				 <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                                <exclude>**/Log4j2Plugins.dat</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<finalName>fat-xxx</finalName>
						</configuration>
					</execution>
				</executions>

解决方法:

设置下面参数

spring.cloud.compatibility-verifier.enabled=false

23. Eureka datacenter and environment not displayed on the Eureka dashboard

问题:Eureka  server 页面的datacenter和environement 显示N/A

 原因:

Archaius组件 被Spring cloud 移除了,

移除之前org.springframework.cloud.netflix.eureka.server.EurekaController类中代码如下:

model.put("environment",
				ConfigurationManager.getDeploymentContext().getDeploymentEnvironment());
model.put("datacenter",
				ConfigurationManager.getDeploymentContext().getDeploymentDatacenter());

移除之后代码如下:

		model.put("environment", "N/A"); // FIXME:
		model.put("datacenter", "N/A"); // FIXME:

解决方法:

从spring-cloud-netflix-eurak-server-3.1.1.jar中复制EurekaController.java,然后下面改动

public class EurekaController {

	@Value("${eureka.environment:test}")
	private String environment;

	@Value("${eureka.datacenter:default}")
	private String datacenter;

    model.put("environment", environment);
	model.put("datacenter", datacenter);

参考资料

https://github.com/spring-cloud/spring-cloud-netflix/issues/4032

24. /actuator/info Endpoint 节点显示不出来信息了 

升级之前,如果我们在application.properties 定义了如下属性,你访问actuator/info节点时会有这些信息出来的。

info.app.name=@project.artifactId@
info.app.description=@project.description@
info.app.version=@project.version@
info.app.encoding=@project.build.sourceEncoding@
info.app.java.source=@java.version@
info.app.java.target=@java.version@

解决方法:

在application.properties 加下面属性

management.info.env.enabled = true

其它相关知识

Spring-boot 2.6.2版本所依赖的包。里面包含spring5.3.14版本.

Dependency Versionshttps://docs.spring.io/spring-boot/docs/2.6.2/reference/html/dependency-versions.html#dependency-versions

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐