YAZONG 我的开源

汇总自2017年11月至今使用springboot框架(包括集成中间件等)的异常和解决方案

 
0 评论0 浏览

#201907 官方推荐 springboot2.1.X 版本,1.5.X 版本在 201908 不再维护。

1、

springboot1.5.10 以下版本(包括本版本)支持 Spring 版本为 4.3.13,现在用官网推荐版本 1.5.9,是 2017 年出的
springboot2.0 以上版本最低支持 spring5.0

所有支持的 jar 包的版本号在官网每个版本号 API 文章的最下方
image.png

2、

2017-12-27 20:36:55.700 WARN 9696 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cityRestController': Unsatisfied dependency expressed through field 'cityService';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cityServiceImpl': Unsatisfied dependency expressed through field 'cityDao';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cityDao' defined in file [E:\doc\learning\workspace\springbootlearning\springboot-learning-example\springboot-learning-example\springboot-mybatis-redis\target\classes\org\spring\springboot\dao\CityDao.class]:
Unsatisfied dependency expressed through bean property 'sqlSessionFactory';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]:
Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]:
Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.NullPointerException

在 application.properties 这个配置文件中一定要把 MySQL 数据源配置好,不要错一个字,这种错误不好找,实在找不出错误,就从正确的项目中找个 copy 一下,重新 clean 和 install、启动即可。

3、

java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [org.spring.springboot.domain.City]

City 这个实体要实现 Serializable,不然就报上述错误。

调用代码的地方是
image.png

4、

java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.
You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springbootdb?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC

链接最后加入&serverTimezone=UTC

5、

启动的时候,比如报"beetlconfig"问题,在同一个包下,可能是冲突了。
当我点击控制台的"beetlconfig"时,跳到了其他项目的 Spring 的 XML,所以换个项目路径就行了。

6、

垃圾问题略,不需要加入,是 Web 容器问题
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beetlConfig' defined in class path resource [com/idengyun/media/boot/context/BeetlConf.class]: Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext

javax.servlet.jsp.jstl jstl-api 1.2 org.glassfish.web jstl-impl 1.2

7、

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
启动项目的类中加入
@Bean
public EmbeddedServletContainerFactory servletContainer() {

}

8、

NoClassDefFoundError: org/apache/catalina/Host
Tomcat 的 lib 包中的 catalina.jar 和

org.apache.tomcat.embed
tomcat-embed-jasper
provided

中的 Host 的类冲突。但是去掉这个 jar 包就行了。

org.springframework.boot
spring-boot-starter-tomcat
provided

9、

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [sample.jsp.SampleWebJspApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
(不要看见上述的 servlet 问题就添加 servlet 相关的 jar 包或者添加 Tomcat 作为依赖)

不要直接运行 main 方法启动,而是在控制台执行 mvn clean spring-boot:run -Dspring.profiles.active=dev 来启动项目。

或者在 IDEA 的 EDIT CONFIGURATIONS 上选择 maven,在 Command line 中输入:clean spring-boot:run -Dspring.profiles.active=dev,即可,但是得手工关闭端口。
image.png

但是上述有个问题,这种启动以后,点击停止运行项目后,端口关不掉,必须在进程中自己杀死。

可以关掉端口的方式是从 DOS 中执行上述命令,当想停止项目的时候,按 ctrl+c 之后输入 Y 即可。

10、

首先,thymeleaf 和 JSP 就不应该结合起来,两者是同类东西,就应该二选一。
其次,JSP 真的不推荐使用了,连 Spring Boot 官方都嫌弃了,出了问题,Spring Boot 团队开发都搞不定,更何况我们作为框架的使用方。
JSP 和 Thymeleaf 是两套不同的模板。
JSP 是 JavaEE 的规范,但 JSP 显然已经 out 了。毕竟不合适前后端分离的项目。
技术应用是要结合应用场景的,如果单纯从学习角度来看,学习哪个技术都没有错。但如果是要做产品,做项目,那技术选型就非常关键了。

JSP 只能在 WEB-INF/XX 下使用,不能在 resources 目录下使用。

11、

在能使用 JSP 的前提下加入

结果是 HTML 能访问,JSP 不能访问。
template might not exist or might not be accessible by any of the configured Template Resolvers

template 标签,HTML 和 JSP 不能共存!

同上述 10.

12、

在类名的上面配置下述内容时
@PropertySource("classpath:/properties/testproperty.properties")
@ConfigurationProperties(prefix = "test1")
报"springboot configuration annotation processor not found in classpath"。
在 MAVEN 中配置下述内容

org.springframework.boot
spring-boot-configuration-processor
true

或者在 GRADLE 中配置下述内容
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
compileJava.dependsOn(processResources)
上述对应官网介绍在
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor
中的"B.3 Generating your own meta-data using the annotation processor"内容里。

13、

server.context-path 的值应该是加斜杠的“/testbootpro”,而不是“testbootpro”
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: ContextPath must start with '/' and not end with '/'

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
改成
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

对应

MySQL
mysql-connector-java
6.0.6

14、

#设置成 LEGACYHTML5 可以防止在 HTML 中缺少结束标签页面报错,同时在 pom.xml 中需要配置 nekohtml
spring.thymeleaf.mode=LEGACYHTML5

15、

java.lang.IllegalStateException: Could not initialize Logback logging from classpath:xml/logback-context.xml
Caused by: ch.qos.logback.core.LogbackException: Unexpected filename extension of file [file:/home/workspace/htdocs/ym-wap/ym-wap/WEB-INF/classes/xml/logback-context.xml/]. Should be either .groovy or .xml

Linux 环境被编译成了
logging.config=classpath:/xml/logback-context.xml/目录,而不是文件

要配置成 logging.config=classpath:/xml/logback-context.xml
事先没在 XML 前加反斜杠

16、

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
启动类必须在某个包下,不能直接在/src/main/java 下。

17、

当一个 bean 声明为 dev 或 prod(@Profile("dev"))时,如果这个 bean 是在不同运行环境声明的,那么就不要在其他 bean 中注入这个 bean,是 dev 的,就注入 dev 的 bean,其他同理。
@Autowired
private T t;

不然报错如下:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'doctorController': Unsatisfied dependency expressed through field 'prodProfile'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.idengyun.ym.common.springboot.base.BaseProjectProdProfile' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

18、

在 maven 中配置如下:

fzx-contest-web


org.springframework.boot
spring-boot-maven-plugin
1.5.9.RELEASE
......

......

那么在此项目中必须要有 SpringBoot 的启动类,而且此启动类要放在根目录中,要防止不能扫描到配置类,分布式项目同理。

19、

在用 SpringBoot 做分布式项目时,一定要注意运行 SpringBoot 的 main 方法主类一定要在所有类的根目录,可能出现的情况是,类无法正常注入等。

20、

10:56:51.317 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'
(上述这句话在是否解决下述问题时都会打印,所以在找问题时,要从根源先找。)
(
打开 StandardServletEnvironment,由于下述的错误是跟 JNDI 有关,所以看下这个类中处理 JNDI 的方法,可以查看到不同的版本的这部分代码并没有改动。
image.png

spring4.3.X 版本中加入了 JNDI 的判断,Spring 低版本的这个方法中并没有 JNDI 的判断。点击布尔值 shouldIgnoreDefaultJndiEnvironmentshouldIgnoreDefaultJndiEnvironment,可看到对应的值为 spring.jndi.ignore,
这个值是从对象 SpringProperties 中得到的,对应的加载文件是 spring.properties。

)
10:56:51.948 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception-conversion-word]
10:56:51.949 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception-conversion-word] not found - trying original name [logging.exception-conversion-word]. javax.naming.NameNotFoundException: Name [logging.exception-conversion-word] is not bound in this Context. Unable to find [logging.exception-conversion-word].
10:56:51.949 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exception-conversion-word]
10:56:51.949 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [logging.exception-conversion-word] threw NamingException with message: Name [logging.exception-conversion-word] is not bound in this Context. Unable to find [logging.exception-conversion-word].. Returning null.
10:56:51.949 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception_conversion_word]
10:56:51.949 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception_conversion_word] not found - trying original name [logging.exception_conversion_word]. javax.naming.NameNotFoundException: Name [logging.exception_conversion_word] is not bound in this Context. Unable to find [logging.exception_conversion_word].

在 resources 目录建立 spring.properties 文件,加入 spring.jndi.ignore=true 即可。

http://blog.csdn.net/qq_30739519/article/details/78536965

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed19fa950d100b96204a05d93e788090412189d65f93130a1c187ba0fc7063565f8e993d7a07af4f5aeef235732a4262f7c094dd5dddcdca7479d330340642db14478845fadc46539177c407a9f80ee7ccae6fc6fe8182864353bc08446d8086d0065b52913cae4f79b4f08d0d481f46b5bc6d39bb0e376fc87557b636a1bc6435108187810f13943dd0100697de22b14e4ae657f7081a5453a13fa60921776dbf0d30ff356a58d6fc5d9674241576ed14e6aec0c6fc48fbcbeb41daa98de978d53cf1c49aee713567538a7be9efeaec2a643415d9bbc917b46ee1bcfbba3dbd49904c0a&p=987fcc16d9c15aff57ed947e1e5586&newp=c93bde0186cc41af58aee62d02148e231610db2151d7d6126b82c825d7331b001c3bbfb423251003d5c6786d01aa4958edf0367033012ba3dda5c91d9fb4c57479cb55&user=baidu&fm=sc&query=Converted+JNDI+name+%5Bjava%3Acomp/env/logging%2Epattern%2Elevel%5D+not+found&qid=a840e9bc00005120&p1=4

https://jira.spring.io/browse/SPR-14026

21、

Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

如果是 jar 启动,那么 pom.xml 中不要再引入外置 Tomcat 配置。

22、

logback.xml 配置发送邮件

java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [ch.qos.logback.classic.net.SMTPAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.net.SMTPAppender
ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:76 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.net.SMTPAppender
ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [email]. Did you define it below instead of above in the configuration file?
ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.

要在 pom.xml 中配置 javax.mail 的 jar。

23、

spring.resources.static-locations 是否配置的区别,如果配置 spring.resources.static-locations,那么 swagger 是不能正常访问的。
这里,spring.resources.static-locations 默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,所以不用配置,
因为 swagger 的访问路径为 http://localhost:9331/swagger21/swagger-ui.html,swagger-ui.html 在 springfox-swagger-ui-2.7.0.jar 的 resources 目录下,
如果非要配置上述属性,那么这个访问不到,也要注意访问项目资源的过滤器问题的改造。

24、

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
Disconnected from the target VM, address: '127.0.0.1:49234', transport: 'socket'
java.lang.ExceptionInInitializerError

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.
Either remove Logback or the competing implementation
(class org.slf4j.impl.Log4jLoggerFactory loaded from file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar).
If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory

24、1

解决方案 1
使用 SpringBoot 下述自带的 log 包括了好多日志

org.springframework.boot
spring-boot-starter-logging
${spring.boot.version}

去掉下述所有其他日志配置即可

org.slf4j
slf4j-log4j12
$ {slf4j.log4j12.version}

org.apache.logging.log4j log4j-to-slf4j ${log4j.version} org.apache.logging.log4j log4j-core ${log4j.version} org.apache.logging.log4j log4j-api ${log4j.version} ch.qos.logback logback-core ${logback.version} ch.qos.logback logback-classic ${logback.version}

24、2

解决方案 2
由于自己封装的 jar 包中存在 logback 等 jar 包,要引入其他 jar 包,解决方案是用 springboot-logging 替换,但是一定得把 springboot-logging 放在其他封装 jar 包的最上面,
可以理解成 pom.xml 也是从上往下编译的,springboot-logging 囊括了 slf4j 和 logback 等日志,为防止冲突,用 springboot-logging 来覆盖其他日志的 jar。
案例如下:

org.springframework.boot spring-boot-starter-logging 1.5.9.RELEASE com.idengyun fzx-rpc-interface-client 1.0.0 jar com.idengyun fzx-rpc-interface-module 1.0.0 jar com.idengyun fzx-rpc-interface-auto 1.0.0 jar

24、3

上面的方案没解决透彻
在 SpringBoot 的配置中用到了 logback 和 slf4j,但是在项目启动时报错如下
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
上面很明显的问题,同一个类,有多个 jar 包导致使用类冲突。
网络中的方案是在 slf4j 中排除 logback,当尝试完未果,而且发现在 Linux 启动时也报 logback 未发现 class 的错误,突然逆向思考一下,想是从排除 slf4j,当点开 zookeeper 配置时也引入了其他的日志包,在 zookeeper 的 client 操作工具中也发现排除了 zookeeper 配置,所以直接在 zookeeper 的配置中排除掉 slf4j。

org.apache.zookeeper zookeeper ${zookeeper.version} org.slf4j slf4j-log4j12 org.apache.curator curator-recipes ${zookeeper.curator.version} org.apache.zookeeper zookeeper

24、4

SpringBoot 结合 zookeeper 项目启动问题:

SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.

zookeeper 3.4.11 中的 slf4j 版本是 1.6
而现在项目中的 slf4j 的相关版本是 1.7+
zookeeper 3.4.12 中的 slf4j 版本是 1.7+,zookeeper 版本号改成 3.4.12,并排除下述 slf4j 的相关 jar 即可。

org.apache.zookeeper zookeeper ${zookeeper.version} org.slf4j slf4j-log4j12 org.slf4j slf4j-api

25、

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

启动类不要直接放在 src 目录下,放在新建的包下(能扫描到所有的文件的路径下)

26、

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
要在 ES 的配置上面配置 log4j-core

org.apache.logging.log4j log4j-core ${apache.log4j.core.version} org.elasticsearch.client transport ${org.elasticsearch.version} org.elasticsearch.plugin transport-netty4-client ${org.elasticsearch.version} org.elasticsearch elasticsearch ${org.elasticsearch.version}

不然的话,报错:
Factory method 'getTransportClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil

27、

27、1

现在项目的 SpringBoot 是 1.5.10.RELEASE 版本,当引入 spring.boot.mybatis.version1.3.1 时,项目运行的时候 springboot1.5.6.RELEASE 版本,
如果要使用 1.5.10.RELEASE 版本,那么需要升级 spring.boot.mybatis.version 为 1.3.2

27、2

在引入 druid 时,需要引入下述所有的,如果不引入 druid,那么也会导致 SpringBoot 版本启动为 1.5.6,并且抛异常找不到 JDBC。

com.alibaba druid-spring-boot-starter 1.1.6 com.alibaba druid 1.1.6

28、

在项目中加入了 AOP 处理类,扫描了 service 路径。
由于在项目启动时,通过注解的方式,由子类 service 名称获取子类接口实现类的代理,这里默认使用了 JDK 代理,导致不能获取对象,

Mapstring,object thriftEnableBusinessAnnotationBeans
= applicationContext.getBeansWithAnnotation(ThriftEnableBusinessAnnotation.class);
if (null == thriftEnableBusinessAnnotationBeans || thriftEnableBusinessAnnotationBeans.isEmpty()) {
return;
}
Mapstring,string matchBusinessBeanMap = thriftMatchConditionBean.getMatchBusinessBeanMap();
thriftEnableBusinessAnnotationBeans.entrySet().forEach((entry) -> {
String serviceBeanName = entry.getKey();
Object bean = applicationContext.getBean(serviceBeanName);
//获取定义此注解的所有 bean 中的业务类型 businessName
Class clz = bean.getClass();
boolean clzHasAnnotation = clz.isAnnotationPresent(ThriftEnableBusinessAnnotation.class);
if(clzHasAnnotation){
ThriftEnableBusinessAnnotation thriftEnableBusinessAnnotation =
(ThriftEnableBusinessAnnotation) clz.getAnnotation(ThriftEnableBusinessAnnotation.class);
String businessName = thriftEnableBusinessAnnotation.getBusinessName();
//组装 zookeeper 某业务模块下的 service 的值
matchBusinessBeanMap.put(businessName + "&" + serviceBeanName,
initZookeeperInitDataBean(businessName,serviceBeanName));
}
});

@Service("rpcServerTestService")
@ThriftEnableBusinessAnnotation
(getTypeClass = RpcServerCommonService.class,
getBusinessName = "rpcServerTest")
public class RpcServerTestServiceImpl implements RpcServerCommonService {}

解决方式为在 application-xx.properties 文件中强制 AOP 使用 CGLIB 代理
#设置 AOP 为 CGLIB 代理,对应 ApplicationContextAwareConf 中的注解扫描功能和 RpcServerInterceptor
spring.aop.auto=true
spring.aop.proxy-target-class=true

https://blog.csdn.net/dushenzhi/article/details/52663310

29、

spring.boot.mybatis.version1.3.2

org.mybatis.spring.boot mybatis-spring-boot-starter ${spring.boot.mybatis.version} org.mybatis.spring.boot mybatis-spring-boot-starter-test ${spring.boot.mybatis.version} test

如果配置了上述 MyBatis,那么就必须配置 datasource,不然在项目启动的时候会报找不到 datasource 的异常。

30、

页面 HMTL 必须用模板跳转,如果什么都不配置的话,那么默认是 thymeleaf,即使引入 thymeleaf,不在扫描路径中也不行。

31、

NoClassDefFoundError: org/thymeleaf/templateresolver/TemplateResolver
加入要使用的版本

org.thymeleaf
thymeleaf
2.1.6.RELEASE

32、

java.lang.NoSuchMethodError: org.apache.logging.log4j.ThreadContext.getThreadContextMap()Lorg/apache/logging/log4j/spi/ReadOnlyThreadContextMap;
log4j-api 和 log4j-core 的版本不一致

33、

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.
Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory
loaded from file:/D:/dev/build/maven-3.3.9-jdk8/maven_repo/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar).
If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory

项目中仅需使用一个日志框架 logback 或 log4j。

34、

在 application-xx.properties 等核心配置文件里,不要使用"|"竖线作为分隔符,这样的需要多次转义。

35、

正式环境连接不上 maxscale 中间件

数据库配置:(中间件 maxscale 在阿里生产环境是小版本 2.0,现在迁移后的金山生产环境是小版本 2.2)
(现金山生产环境非 SpringBoot 的 maven 项目可以用 c3p0 连接,但 SpringBoot 的 maven 项目必须用 druid 连接)

market-manage 25-market-manage 27-Aug-2018 18:46:23.198 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 11640 ms
market-manage 25-market-manage 2018-08-27 18:46:30.268 ERROR 29777 --- [pool-1-thread-1] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
market-manage 25-market-manage com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
market-manage 25-market-manage The last packet sent successfully to the server was 2 milliseconds ago. The driver has not received any packets from the server.

market-manage 25-market-manage org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

market-manage 25-market-manage org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

market-manage 25-market-manage Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceConnectionMap' defined in class path resource [com/idengyun/market/common/springboot/db/DataSourceInitConf.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.Map]: Factory method 'getDataSourceConnectionMap' threw exception; nested exception is java.sql.SQLException: 初始化 MySQL 的 c3p0 连接池配置失败,[SQLState:null],[ErrorCode:0],[Message:An attempt by a client to checkout a Connection has timed out.

market-manage 25-market-manage 2018-08-27 19:31:06.611 WARN 15282 --- [Runner@51b231ab] c.m.v2.resourcepool.BasicResourcePool : com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1cdf953a -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

c.m.v2.resourcepool.BasicResourcePool : com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@a6f53b0 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:

market-manage 25-market-manage java.sql.SQLException: Authentication with backend failed. Session will be closed.

market-manage 25-market-manage Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
market-manage 25-market-manage Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
market-manage 25-market-manage Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

Connection killed by MaxScale: Router could not recover from connection errors 由 MaxScale 引发的连接:路由器无法从连接错误中恢复

解决方案:

刚开始以为在 maxscale.cnf 中注释 disable_master_failback = 1 的原因
在阿里正式环境中的 2.0 版本没注释掉上述属性,但现在迁移过后的金山正式环境的 2.2 版本注释掉了上述属性。

我看这两个网站介绍那个属性,大概说是切换 DB 的
https://severalnines.com/blog/deploy-and-configure-maxscale-sql-load-balancing
https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-14/maxscale-readwrite-splitting-with-galera-cluster/+r/43705/
DBA 运维回答:这个参数本来就是自动识别主从的

现在 DBA 运维明确给的答复是,MySQL 在生产是一主二从,通过脚本建库的时候一个从库没建上,导致各种数据库连接池连接不上 maxscale(个人理解是当连接池连接中间件的时候,连接池会连接中间件映射的所有 MySQL 节点地址,当其中一个 MySQL 节点连接失败的时候,客户端就会报错)。

36、

项目刚开始启动就不启动了。
2018-11-06 15:34:27.324 INFO 17616 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-11-06 15:34:27.407 INFO 17616 --- [ main] trationDelegate $BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$ $EnhancerBySpringCGLIB$ $289a97ee] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

最终发现没加

org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE

37、

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpPutFormContentFilter'

#升级
jackson.version2.9.3

38、

Caused by: org.springframework.beans.PropertyBatchUpdateException: Failed properties: Property 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Property 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
不要在 DAO 的扫描路径下加入非 MAPPER 类

39、

启动不打印端口号

方法启动类继承 SpringBootServletInitializer 即可

40、

当要引入其他自定义包时,记得把自定义的放在最后面来引用。比如项目中用的 SpringBoot 版本是 2.X,而引用的 jar 里是 1.5X 的(本身这样就不合理),所以一定要 把引入的 jar 放在最后面。

41、

如果不需要引入其他对象,比如 Redis,那么不要把 Redis 的包和属性配置到项目里,可能会影响,比如 Apollo 等的处理,或者 SpringCloud 的 health 不能正常访问。

42、

在用 Apollo 的时候,配置文件*.yml 中如果配置了日志,记得把日志配置放在 Apollo 的上面,不然可能日志输出可能失败。

43、

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V
Spring 版本不一致导致上述启动异常

jcl、context、core 的 jar 包有 spring5.0.4 还有 spring5.0.8 的,但绝大部分是 spring5.0.8,由于引入的 SpringBoot 是 2.0.4,引入 5.0.8 是正常的,5.0.4 莫名其妙,强制加入 spring-context-support 使 Spring 版本保持一致

org.springframework spring-context-support 5.0.8.RELEASE

44、

Java 操作 Redis 的库有两个,Jedis 和 Lettuce,目前 SpringBoot 2.x 中已经将 Jedis 换成了 Lettuce。

45、

2019-06-20 10:47:58.614 WARN 1429 --- [reactor-http-client-epoll-8] d.c.b.a.s.s.EndpointDetectionTrigger : Unexpected error while handling PooledSlicedByteBuf(ridx: 0, widx: 129, cap: 129/129, unwrapped: PooledUnsafeDirectByteBuf(ridx: 451, widx: 456, cap: 1024))
org.springframework.web.reactive.function.BodyExtractors$ReadCancellationException: null

2019-06-20 10:57:39.709 ERROR 1429 --- [http-nio-8760-exec-5] o.a.catalina.connector.CoyoteAdapter : Exception while processing an asynchronous request
java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH]
at org.apache.coyote.AsyncStateMachine.asyncError(AsyncStateMachine.java:440)

后台配置

46、

2019-06-20 10:47:58.614 WARN 1429 --- [reactor-http-client-epoll-8] d.c.b.a.s.s.EndpointDetectionTrigger : Unexpected error while handling PooledSlicedByteBuf(ridx: 0, widx: 129, cap: 129/129, unwrapped: PooledUnsafeDirectByteBuf(ridx: 451, widx: 456, cap: 1024))
org.springframework.web.reactive.function.BodyExtractors$ReadCancellationException: null

2019-06-20 10:57:40.107 ERROR 1429 --- [http-nio-8760-exec-8] o.a.catalina.connector.CoyoteAdapter : Exception while processing an asynchronous request
java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH]

此项目集成了 springbootadmin,后台启动后一直报上述错误,刚开始一直以为是核心配置文件问题,没注意到版本号,刚开始的版本号为:

org.springframework.boot spring-boot-starter-parent 2.1.0.RELEASE de.codecentric spring-boot-admin-starter-server 2.1.1 org.springframework.cloud spring-cloud-dependencies Finchley.RELEASE pom import

修改版本号为下述内容即可(springcloud 不用动):

org.springframework.boot spring-boot-starter-parent 2.0.6.RELEASE de.codecentric spring-boot-admin-starter-server 2.0.6

从这个问题引发的启发,由于 springbootadmin 读取了 eureka 的内容,而且这里集成了 SpringCloud,无论是哪个工程,版本号都最好对应一致。
springboot2.1.X 和 springboot2.0.X 有一些改变,升级的时候会不可避免的引发一些问题,所以版本号还是对应一致比较靠谱。

在 GitHub 找到的一个相似问题“https://github.com/spring-projects/spring-boot/issues/15057”,从而引发了上述的解决方案和思考。

47、

Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
第一种方案解释:controller 访问的路径、名称不要和 HTML 页面的路径、名称一致
第二种方案解释:在配置文件中配置了"spring.http.converters.preferred-json-mapper=jackson"之后,记得要写一个对应的配置类

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import java.util.ArrayList;
import java.util.List;

@Configuration
@ConditionalOnClass({FastJsonHttpMessageConverter.class})
@ConditionalOnProperty(
name = {"spring.http.converters.preferred-json-mapper"},
havingValue = "fastjson",
matchIfMissing = true
)
public class FastJsonHttpMessageConvertersConfiguration {
@Bean
@ConditionalOnMissingBean({FastJsonHttpMessageConverter.class})
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat,
SerializerFeature.WriteMapNullValue,
SerializerFeature.DisableCircularReferenceDetect //禁止循环引用检测
);
// 中文乱码解决方案
List mediaTypes = new ArrayList<>();
//设定 JSON 格式且编码为 UTF-8
mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
converter.setSupportedMediaTypes(mediaTypes);
converter.setFastJsonConfig(fastJsonConfig);
return converter;
}
}

48、

Cannot call sendError() after the response has been committed
#filter 在服务端跳转后,return 下就解决。

49、

springboot2.1.0 项目里整合了 Redis、MongoDB、Elasticsearch、MySQL、(现在推测再次加入其他中间件也会有下述问题)。启动报下述错误

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:
Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchClientHealthIndicatorAutoConfiguration':
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'transportClient' defined in class path resource [com/idengyun/springboot/conf/elasticsearch/conf/ElasticsearchClientConf.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'getTransportClient' threw exception;
nested exception is java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]

刚开始的解决方案是删除除了 Elasticsearch 的上述所有技术栈,可以正常启动,最后加入 Redis 就不行了,刚开始以为 Redis 某个加载类有冲突,在所有的 Redis 启动配置类中加入@lazy 懒加载尝试下也没解决此问题。

然后是在 main 启动中加入了:System.setProperty("es.set.netty.runtime.available.processors", "false");,解决问题。

可是发现这样并没有实际解决这个问题,再次认真仔细的看了下错误,发现了第二行的黑色字体,又发现了红色字体,突然想到我现在只使用了 SpringBoot 的基本功能,而并没有使用其监控功能,遂想到 pom.xml 中配置了
监控的 jar 包,如下:

org.springframework.boot
spring-boot-starter-actuator

且监控中应该融入了 Elasticsearch 的监控功能。
接着注释此配置,并且把在 main 方法中加入的设置 false 的内容去掉,融入上述所有技术栈,包括 Elasticsearch,启动项目成功。

当再次加入监控时,还会报上述错误,现在的解决方案还是在 main 方法中加入 false 的设置。

由于现在使用的 Elasticsearch 的版本为 6.1.4,找到其源码,搜索"es.set.netty.runtime.available.processors",发现在 Netty4Utils 的下述部分

/**

  • Set the number of available processors that Netty uses for sizing various resources (e.g., thread pools).
  • @param availableProcessors the number of available processors
  • @throws IllegalStateException if available processors was set previously and the specified value does not match the already-set value
    /
    public static void setAvailableProcessors(final int availableProcessors) {
    // we set this to false in tests to avoid tests that randomly set processors from stepping on each other
    final boolean set = Booleans.parseBoolean(System.getProperty("es.set.netty.runtime.available.processors", "true"));
    if (!set) {
    return;
    }
    /
    • This can be invoked twice, once from Netty4Transport and another time from Netty4HttpServerTransport; however,
    • Netty4Runtime#availableProcessors forbids settings the number of processors twice so we prevent double invocation here.
      /
      if (isAvailableProcessorsSet.compareAndSet(false, true)) {
      NettyRuntime.setAvailableProcessors(availableProcessors);
      } else if (availableProcessors != NettyRuntime.availableProcessors()) {
      /
      • We have previously set the available processors yet either we are trying to set it to a different value now or there is a bug
      • in Netty and our previous value did not take, bail.
        */
        final String message = String.format(
        Locale.ROOT,
        "available processors value [% d] did not match current value [% d]",
        availableProcessors,
        NettyRuntime.availableProcessors());
        throw new IllegalStateException(message);
        }
        }

通过方法描述可知,设置 false 可以避免由于各种处理器(可理解成引入 netty 的各种中间件)的互相测试而互相干扰导致的各种各样的问题,所在直接在 main 方法中加入这种设置项即可根本性解决问题。

从而可知,网络上搜索出来的答案并不严谨,比如 netty 版本、Lucene 等,这些并没有从本质上解决问题。

50、

Error running 'MtmySearchGoodsApplication': Command line is too long. Shorten command line for MtmySearchGoodsApplication or also for Application default configuration

image.png

51、

NoClassDefFoundError: org/yaml/snakeyaml/LoaderOptions

org.yaml snakeyaml 1.25

52、

如果要设置 program arguments,那么这个可以在 IDEA 中设置,也可以在 main 方法的参数中去设置,这个不是 JVM 的参数,不要在使用 Java 命令时使用"--xx"的操作。

53、

2019-12-25 09:23:18.621 ERROR 26658 --- [http-nio-8609-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for serv
let [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.
web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary
upload location [/tmp/tomcat.7020477665693839976.8609/work/Tomcat/localhost/ROOT] is not valid] with root cause
java.io.IOException: The temporary upload location [/tmp/tomcat.7020477665693839976.8609/work/Tomcat/localhost/ROOT] is not valid

在 SpringBoot 项目启动后,系统会在‘/tmp’目录下自动的创建几个目录:
drwxr-xr-x 2 microservices microservices 4096 Dec 25 14:12 hsperfdata_microservices
drwxrwxr-x 3 microservices microservices 4096 Dec 25 11:35 tomcat.7470356219304488804.8609
drwxrwxr-x 3 microservices microservices 4096 Dec 25 14:11 tomcat.8263480967527603889.8609
drwxrwxr-x 3 microservices microservices 4096 Dec 25 12:19 tomcat.8561695159347564868.8610
drwxrwxr-x 3 microservices microservices 4096 Dec 25 11:39 tomcat.9010298987586309950.8610
drwxrwxr-x 2 microservices microservices 4096 Dec 25 11:39 tomcat-docbase.1581218210455101491.8609
drwxrwxr-x 2 microservices microservices 4096 Dec 25 14:12 tomcat-docbase.4078053852872190090.8610

查阅资料后,发现是 CentOS 对'/tmp'下文件自动清理的原因。
tmp 文件夹 有个特性 ,就是在 10 天内没有进行操作,该文件夹内的文件夹和文件等就会自动被清除,导致一些文件丢失。
可编辑/usr/lib/tmpfiles.d/tmp.conf 文件,在最下面加入 x /tmp/tomcat.*,不让系统自动删除这个文件。

解决方法:
方法一:直接从新启动项目即可解决(这个只能治标不治本)
方法二:指定上传文件临时的路径(从根本解决)(个人用的这种)
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
String location = System.getProperty("user.dir") + "/data/tmp";
File tmpFile = new File(location);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
factory.setLocation(location);
return factory.createMultipartConfig();
}

方法三:(没用,现有的 spring5 版本已去除此属性)
在 propertites 文件中配置: spring.http.multipart.location= 你的缓存文件路径

54、

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory'
defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]:
Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError:
org/apache/commons/pool2/impl/GenericObjectPoolConfig

redis.clients jedis 2.9.0

55、

启动报配置文件加载不了 application-xx.yml
duplicate key: Spring

yml 文件中相同开头的 key 要放在一起

56、

main
com.ctrip.framework.apollo.configservice.ConfigServiceApplication

VM
-Dapollo_profile=github -Dlogging.file=/application/project/apollo/logs/100003171/apollo-configservice.log -Dspring.datasource.url=jdbc:mysql://127.0.0.1:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=yalong -Dspring.datasource.password=yalong

Program arguments
--spring.profiles.active=fat

在 ConfigurableEnvironment environment = new StandardEnvironment();中,会把上述参数 Program arguments 放入环境变量,所以要在启动的时候事先配置好。
https://github.com/chillzhuang/SpringBlade这种 SpringBoot 启动重写启动的 build 对象时,就需要提前设置相关参数。

57、

${LOG_FILE} 14 512MB .......略.......日志文件大小一定要配在上面,而不是这里,对应springboot版本2.1.0 .......略.......

58、

com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed

操作系统没内存了

59、

在一个 A 项目中要引入 spring-security-oauth2,要使用 2.3.5.RELEASE 版本,可是现在进行 tar 打包后,引入的版本是 2.2.4.RELEASE 版本,发现依赖父项目中的 SpringBoot 版本是 2.1.13(202002 发布),默认引入的 spring-security-oauth2 版本就是 2.2.4.RELEASE 版本。
Spring 版本 Spring 5.1.10(201909 发布)。那么在 A 项目中可以使用下述方法解决版本问题。

org.springframework.security.oauth spring-security-oauth2 2.3.5.RELEASE org.springframework.security.oauth spring-security-oauth2 2.3.5.RELEASE

因为现在的项目已经开发趋于稳定,没必要因为一个版本号,而升级全局的 SpringBoot 版本而导致一些不必要的问题。

60、

关于引入 spring-data-redis 版本的问题,同上。
spring-data-redis-1.8.0 的 Redis 版本是 2.9.0
spring-data-redis-2.1.16 的 Redis 版本是 2.9.3

发现上述 spring-security-oauth2(封装了 Redis 和 MySQL 等)如果是 2.2.4 的版本,那么 Redis 版本过低,导致处理 Redis 的值失败。

所以在引入各个包时,要注意各个版本的包的版本问题,时间问题,时间跨度问题,版本跨度问题。
不值得因为某个版本的包的问题而整体升级框架版本,即使是兼容的。
要注意引入包中的其他子包的版本问题。
一个框架中最能有一个 Spring 版本的 context 上下文。

60、

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

在 application.properties/或者 application.yml 文件中没有添加数据库配置信息。
spring:
datasource:
url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver

61、

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

启动 SpringBoot 项目,只打印端口,不输出下述日志,是没真正起来的。当然这个端口进程也没有。

2020-08-22 13:38:01.111 INFO 1682 --- [XNIO-1 task-1] io.undertow.servlet : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-08-22 13:38:01.112 INFO 1682 --- [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-08-22 13:38:01.129 INFO 1682 --- [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 17 ms
2020-08-22 13:38:01.359 INFO 1682 --- [parallel-1] io.lettuce.core.EpollProvider : Starting without optional epoll library
2020-08-22 13:38:01.360 INFO 1682 --- [parallel-1] io.lettuce.core.KqueueProvider : Starting without optional kqueue library

1)关闭防火墙即可。
systemctl status firewalld.service
systemctl stop firewalld.service
2)如果 SpringBoot 版本是 1.5 或 2.0,且操作系统是 7.1/7.2 的,那么迁移到 7.7 版本时,一定要把 SpringBoot 版本升级到 2.1.X。
3)JDK8 版本一定要用最高的 release 版本,不要用(初始迭代)低版本。


标题:汇总自2017年11月至今使用springboot框架(包括集成中间件等)的异常和解决方案
作者:yazong
地址:https://blog.llyweb.com/articles/2020/08/24/1598234795191.html