1.去除springboot-starter的log4j依赖:
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-logging
2.引入log4j2
org.springframework.boot
spring-boot-starter-log4j2
3.dubbo-springboot的依赖不需要去除log4j,在依赖树中只能看到接口层的slf4j,可以兼容log4j2,所以不需要更改
com.alibaba.boot
dubbo-spring-boot-starter
4.更改配置信息:
UTF-8
UTF-8
1.8
debug
/opt/appstack/apache-tomcat/logs/${project.name}
/opt/appstack/apache-tomcat/logs/${project.name}-error
/opt/appstack/apache-tomcat/logs/${project.name}-kk
5.在resources目录下新建log4j2-spring.xml
log4j2|%d{yyyy-MM-dd HH:mm:ss.SSS} | -%-5level [%thread] %c [%L] -| %msg%n
6.思考
其实上面的步骤,基本上亦可以被用来更换springboot默认使用的logback日志应用层,因为dubbo-spring-boot-starter这个依赖中,我本以为需要去除log4j,在网上查了很久,都查不到这个依赖的信息,查看依赖等级之后没有看到log4j的依赖,此处存疑,希望有人能告诉我结果.
7.其他问题:
maven的依赖都是很多层的关系,稍有不慎就会出现问题,在我这个项目中,同样出现一个很奇怪的bug,那就是出现服务层消费者在调用提供者的服务时,出现java.lang.ClassCastException的错误,可是明明对象都是一个,经过查询得知,是springboot dev tools的问题,这里需要去除这个依赖
org.springframework.boot
spring-boot-devtools
true
另外,如果出现跟数据源有关的错误的时候,
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
需要在启动类的注解
@SpringBootApplication()加入exclude = DataSourceAutoConfiguration.class--->
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)