Spring Boot 1.1.8.RELEASE依赖于spring-boot-starter-web导致对hibernate-validator的依赖,而hibernate-validator依赖于jboss-logging。
对jboss-logging的依赖导致jboss日志记录通过logback接管日志记录输出,这也是一个依赖项,并且是spring-boot的常用记录器。至少,这就是我发生的事情。即使在启动时指定logback.configurationFile系统属性,也会完全忽略logback.xml文件。
我知道可以在maven或gradle中排除jboss-logging,但这真的需要吗? spring-boot-starter-web应该指定排除本身吗?
这是应用程序启动时的输出:
12:56:42,137 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
12:56:42,145 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.0.3.Final
12:56:42,206 [main] DEBUG o.h.v.i.e.r.DefaultTraversableResolver - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
但是如果你在maven中使用exclude删除了jboss-logging依赖项,那么在运行时你会从应用程序上下文启动中获得一个堆栈跟踪。
16:56:30,956 [main] WARN o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) ~[spring-beans-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:199) ~[spring-context-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:620) ~[spring-context-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467) ~[spring-context-4.0.7.RELEASE.jar!/:4.0.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) [spring-boot-1.1.8.RELEASE.jar!/:1.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.1.8.RELEASE.jar!/:1.1.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.1.8.RELEASE.jar!/:1.1.8.RELEASE]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142) [spring-boot-1.1.8.RELEASE.jar!/:1.1.8.RELEASE]
at com.infor.cloud.dojo.manager.server.Application.main(Application.java:283) [infor-cloud-dojo-manager-server-20141022T1625.jar!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) [infor-cloud-dojo-manager-server-20141022T1625.jar!/:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20]
Caused by: java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
谢谢,
-Don