1
votes

I want to create easy Spring MVC project.

And I got:

Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory

Here is snippet of pom.xml:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>3.2.0.RELEASE</spring.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.7</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.4.1</version>
    </dependency>

    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>

servlet-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven/>

    <!--<mvc:resources location="assets" mapping="/assets/**"/>-->
    <mvc:resources location="pdfs" mapping="/pdfs/**"/>

    <context:component-scan base-package="lelyak.demo"/>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1"/>
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManager">
                <constructor-arg>
                    <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
                        <constructor-arg>
                            <map>
                                <entry key="json" value="application/json"/>
                                <entry key="xml" value="application/xml"/>
                            </map>
                        </constructor-arg>
                    </bean>
                </constructor-arg>
            </bean>
        </property>

        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <constructor-arg>
                        <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
                            <property name="autodetectAnnotations" value="true"/>
                        </bean>
                    </constructor-arg>
                </bean>
            </list>
        </property>
    </bean>

    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language"/>
    </mvc:interceptors>

    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>

    <bean id="messageSource"
          class="org.springframework.context.support.ResourceBundleMessageSource"
          p:basename="messages"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="2"/>

    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>
</beans>

I couldn't figure out why this happen. And how to solve this trouble.

UPDATE:

output after mvn -Dverbose dependency:tree:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ ProjectFromConsoleDemo ---
[INFO] lelyak.demo:ProjectFromConsoleDemo:war:1.0
[INFO] +- org.springframework:spring-webmvc:jar:3.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.2.0.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-aop:jar:3.2.0.RELEASE:compile
[INFO] |  |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-beans:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-expression:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-beans:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-core:jar:3.2.0.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework:spring-web:jar:3.2.0.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-context:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-aop:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  \- (org.springframework:spring-beans:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-expression:jar:3.2.0.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-beans:jar:3.2.0.RELEASE:compile
[INFO] |     \- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
[INFO] |  \- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
[INFO] |  +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.7.7)
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.4.1:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.4.1:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] \- org.springframework:spring-oxm:jar:3.2.0.RELEASE:compile
[INFO]    +- (org.springframework:spring-core:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO]    +- commons-lang:commons-lang:jar:2.5:compile
[INFO]    \- (org.springframework:spring-beans:jar:3.2.0.RELEASE:compile - omitted for duplicate)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Any suggestions?

1
By any chance do you have slg4j jar at multiple places?SMA
@almasshaikh I misunderstood your point.catch23
mvn -Dverbose dependency:tree tells you if you have different jars in maybe conflicting versions in your build. Look for the logging jars.bjoernhaeuser
@bjoernhaeuser I updated question.catch23
@nazar_art which container are you using? It seems that your container ships with a conflicting versions of one of the logging jars.bjoernhaeuser

1 Answers

0
votes

Solution was cleaned - webapps folder at Tomcat.

I deleted old projects which were deployed. And now it works fine.

It has some strange impact on my application.