spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.57k stars 40.55k forks source link

Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory #4025

Closed edwardlau closed 8 years ago

edwardlau commented 8 years ago

I deploy war file to resin this springboot version 1.25 the jar is:

antlr-2.7.7.jar
aopalliance-1.0.jar
aspectjrt-1.8.6.jar
aspectjweaver-1.8.6.jar
classmate-1.0.0.jar
commons-codec-1.9.jar
commons-lang3-3.4.jar
commons-pool2-2.2.jar
dom4j-1.6.1.jar
druid-1.0.15.jar
fastjson-1.2.6.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.10.Final.jar
hibernate-entitymanager-4.3.10.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-5.1.3.Final.jar
httpclient-4.5.jar
httpcore-4.4.1.jar
jackson-annotations-2.4.6.jar
jackson-core-2.4.6.jar
jackson-databind-2.4.6.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
javax.transaction-api-1.2.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jcl-over-slf4j-1.7.12.jar
jedis-2.5.2.jar
joda-time-2.5.jar
jstl-1.2.jar
jul-to-slf4j-1.7.12.jar
log4j-over-slf4j-1.7.12.jar
logback-classic-1.1.3.jar
logback-core-1.1.3.jar
mybatis-3.3.0.jar
mybatis-spring-1.2.3.jar
newtrace-common-0.0.1-SNAPSHOT.jar
oracle-ojdbc6-11.2.0.3.0.jar
persistence-api-1.0.2.jar
slf4j-api-1.7.12.jar
slf4j-jdk14-1.7.12.jar
slf4j-log4j12-1.7.12.jar
snakeyaml-1.14.jar
spring-aop-4.1.7.RELEASE.jar
spring-aspects-4.1.7.RELEASE.jar
spring-beans-4.1.7.RELEASE.jar
spring-boot-1.2.5.RELEASE.jar
spring-boot-autoconfigure-1.2.5.RELEASE.jar
spring-boot-starter-1.2.5.RELEASE.jar
spring-boot-starter-aop-1.2.5.RELEASE.jar
spring-boot-starter-data-jpa-1.2.5.RELEASE.jar
spring-boot-starter-jdbc-1.2.5.RELEASE.jar
spring-boot-starter-logging-1.2.5.RELEASE.jar
spring-boot-starter-redis-1.2.5.RELEASE.jar
spring-boot-starter-web-1.2.5.RELEASE.jar
spring-context-4.1.7.RELEASE.jar
spring-context-support-4.1.7.RELEASE.jar
spring-core-4.1.7.RELEASE.jar
spring-data-commons-1.9.3.RELEASE.jar
spring-data-jpa-1.7.3.RELEASE.jar
spring-data-redis-1.4.3.RELEASE.jar
spring-expression-4.1.7.RELEASE.jar
spring-jdbc-4.1.7.RELEASE.jar
spring-orm-4.1.7.RELEASE.jar
spring-tx-4.1.7.RELEASE.jar
spring-web-4.1.7.RELEASE.jar
spring-webmvc-4.1.7.RELEASE.jar
tomcat-jdbc-8.0.23.jar
tomcat-juli-8.0.23.jar
validation-api-1.1.0.Final.jar
xml-apis-1.0.b2.jar

when use resinctl start log to pring :

 Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
                        at org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:33) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.LoggerProviders.find(LoggerProviders.java:37) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:32) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getLogger(Logger.java:2163) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2259) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.hibernate.validator.internal.util.logging.LoggerFactory.make(LoggerFactory.java:28) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.internal.util.Version.<clinit>(Version.java:27) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.internal.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:63) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269) ~[validation-api-1.0.0.GA.jar:na]
                        at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
                        at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$Jsr303ValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:381) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
                        at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.afterPropertiesSet(ConfigurationPropertiesBindingPostProcessor.java:174) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
                        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
                        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
                        ... 23 common frames omitted
                     Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
                        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60]
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
                        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_60]
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
                        ... 39 common frames omitted
[2015-09-25 20:04:19]2015-09-25 20:04:19.102 [resin-45] INFO  com.caucho.server.webapp.WebApp - WebApp[production/webapp/tongji.wt.39.net/ROOT] fail
[2015-09-25 20:04:19]2015-09-25 20:04:19.104 [main] WARN  com.caucho.server.webapp.WebApp - java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
                     java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
                        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60]
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
                        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_60]
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
                        at org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:33) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.LoggerProviders.find(LoggerProviders.java:37) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:32) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getLogger(Logger.java:2163) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2259) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214) ~[jboss-logging-3.1.0.CR2.jar:3.1.0.CR2]
                        at org.hibernate.validator.internal.util.logging.LoggerFactory.make(LoggerFactory.java:28) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.internal.util.Version.<clinit>(Version.java:27) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.internal.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:63) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41) ~[hibernate-validator-4.3.0.Final.jar:4.3.0.Final]
                        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269) ~[validation-api-1.0.0.GA.jar:na]

pom.xml is:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.15</version>
        </dependency>

        <dependency>
            <groupId>cn.guoyukun.jdbc</groupId>
            <artifactId>oracle-ojdbc6</artifactId>
            <version>11.2.0.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>net.health</groupId>
            <artifactId>newtrace-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.12</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

org/slf4j/LoggerFactory the jar slf4j-api in the lib why?

zhanhb commented 8 years ago

maybe remove dependency slf4j-log4j12 and slf4j-jdk14 that can solve your problem.

edwardlau commented 8 years ago

I container is resin 4 not support?

zhanhb commented 8 years ago

I'm sorry but I can't reproduce your errors. Could you show what jars are in the project libs and what jars are in your resin libs?I'm sorry but I can't reproduce your errors. Could you show what jars are in the project libs and what jars are in your resin libs?

zhanhb commented 8 years ago

It seems a bug of resin. I test with the latest version of resin(4.0.45). Resin has a jar named jboss-logging-3.1.0.CR2.jar in its lib directory but doesn't have a log4j-api in the directory. ClassLoader of resin won't look for class in the project's lib directory. You can put slf4j-api to the resin/lib to solve the problem.

wilkinsona commented 8 years ago

Thanks for the analysis, @zhanhb

@edwardlau There are two ways to work around the problem:

  1. Copy slf4j-api into resin/lib
  2. Change conf/app-default.xml and add <servlet-hack> to the web-app-default> <class-loader> configuration.

Neither of these is ideal. I've posted to Resin's Google Group. I think that's a better place for this problem as there's nothing we can do in Spring Boot to address it.

matty commented 8 years ago

This is still an issue for Hibernate on Resin, It doesn't seem to load with version 1.3.5 of Spring Boot.

wilkinsona commented 8 years ago

@matty There's nothing that Spring Boot can do about this. See my comment above for how to configure Resin.

matty commented 8 years ago

Do we need to copy the file into resin/lib or can be just add <servlet-hack> and expect the classes to load correctly?

wilkinsona commented 8 years ago

It's two different ways to fix the problem. No need to do both, AFAIK

matty commented 8 years ago

@wilkinsona I have noticed by specifying providedRuntime("org.hibernate:hibernate-validator") and then including hibernate validator 4.3.2.Final it works fine. Maybe it's best to be able to define which hibernate version to use with Spring Boot? I am still aware this is a Resin issue, and hopefully they can fix it.