2
votes

ClassNotFoundException with wicket on Tomcat, Spring and Eclipse during server startup.

In Eclipse when i try to load the server i'm experiencing some errors causing a 404 page.

Here's the stackTrace :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'plop0' defined in ServletContext resource [/WEB-INF/spring-config/dependenciesInjectionContext.xml]: Cannot resolve reference to bean 'plop1' while setting bean property 'plop1'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'plop1': Injection of persistence fields failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.plop2.plop3.presentation.WicketApplication] for bean with name 'wicketApplication' defined in ServletContext resource [/WEB-INF/spring-config/wicketContext.xml]; nested exception is java.lang.ClassNotFoundException: com.plop2.plop3.presentation.WicketApplication
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) 
    ...
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'plop1': Injection of persistence fields failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.plop2.plop3.presentation.WicketApplication] for bean with name 'wicketApplication' defined in ServletContext resource [/WEB-INF/spring-config/wicketContext.xml]; nested exception is java.lang.ClassNotFoundException: com.plop2.plop3.presentation.WicketApplication
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:311)
    ...
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    ... 26 more
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.plop2.plop3.presentation.WicketApplication] for bean with name 'wicketApplication' defined in ServletContext resource [/WEB-INF/spring-config/wicketContext.xml]; nested exception is java.lang.ClassNotFoundException: com.plop2.plop3.presentation.WicketApplication
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
    ...
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:308)
    ... 37 more
Caused by: java.lang.ClassNotFoundException: com.plop2.plop3.presentation.WicketApplication
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    ...
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
    ... 49 more

The pom.xml of plop3-admin-provider-wicket :

<parent>
    <groupId>com.plop2.plop3</groupId>
    <artifactId>plop3</artifactId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
</parent>

<artifactId>plop3-admin-provider-wicket</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}(${project.packaging})</name>

<dependencies>
    ...
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    ...
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket</artifactId>
    </dependency>       
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-extensions</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-datetime</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-jmx</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-spring</artifactId>
    </dependency>
</dependencies>
<build>
    <resources>         
        <resource>
            <filtering>true</filtering>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.html</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <filtering>true</filtering>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>
</build>

The pom.xml of plop3-admin-war:

<parent>
    <groupId>com.plop2.plop3</groupId>
    <artifactId>plop3</artifactId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>plop3-admin-war</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}(${project.packaging})</name>
<dependencies>      
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>plop3-admin-provider-wicket</artifactId>
    </dependency>       
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    ...
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket</artifactId>
    </dependency>
    ...
</dependencies>
<build>
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/webapp</directory>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

The web.xml of plop3-admin-war :

<!-- Spring param -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-config/applicationContext.xml</param-value>
</context-param>
<filter>
    <filter-name>Spring character encoding filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>Spring character encoding filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>gassi.filter</filter-name>
    <filter-class>com.plop2.plop3.gassi.GassiFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>gassi.filter</filter-name>
    <url-pattern>/app/*</url-pattern>
</filter-mapping>   
<filter>
    <filter-name>wicket.filter</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationFactoryClassName</param-name>
        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
    </init-param>
    <init-param>
        <param-name>configuration</param-name>
        <param-value>${configuration.type}</param-value>
    </init-param>
</filter>   
<filter-mapping>
    <filter-name>wicket.filter</filter-name>
    <url-pattern>/app/*</url-pattern>
</filter-mapping>
<listener>
    <display-name>spring context loader</display-name>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Listener applicatif -->
<listener>
    <display-name>plop3Listener context loader</display-name>
    <listener-class>com.plop2.plop3.plop3Listener</listener-class>
</listener>

The /plop3-admin-war/src/main/webapp/WEB-INF/spring-config/applicationContext.xml :

<import resource="applicationPropertiesContext.xml" />
<import resource="dependenciesInjectionContext.xml" />  
<import resource="jpaDaoContext.xml" />
<import resource="transactionContext.xml" />
<import resource="wicketContext.xml" />

Then the /plop3-admin-war/src/main/webapp/WEB-INF/spring-config/wicketContext.xml :

<bean id="wicketApplication" name="wicketApplication"
    class="com.plop2.plop3.presentation.WicketApplication" scope="singleton">
</bean>

I don't understand why the class couldn't be loaded, the plop3-admin-provider-wicket is present in the plop3-admin-war Maven Dependencies list.

It's drive me crazy, two days that i'm on it.

1
Does the war contains your wicket library on WEB-INF lib ?Cristian Meneses
Yes the Wicket libraries are present in the Maven Dependancies list. Originaly, the projet was developed to run on Jonas server, and still running on it in production environement. In local development whe need to make it run with Tomcat. The projet was created by an other team that is no more, and we just get the project like this.freak0
No, not in the POM, I mean physically on the resulting WAR fileCristian Meneses
Yes also : /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-1.4.9.jar /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-datetime-1.4.9.jar /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-extensions-1.4.9.jar /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-ioc-1.4.9.jar /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-jmx-1.4.9.jar /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/wicket-spring-1.4.9.jar :)freak0
The provider too is present : /echmat-admin-war/target/echmat-admin-war-1.0.0/WEB-INF/lib/echmat-admin-provider-wicket-1.0.0.jarfreak0

1 Answers

1
votes

Try building a WAR and deploying it to a tomcat running completely outside eclipse, by dropping the WAR in the webapps directory and running the launch script.

This will determine if the problem is the library dependencies or in the eclipse workspace setup.

If you suspect the workspace setup, try closing all projects in eclipse and deleting them from the workspace. Do a mvn clean install from the command line and make sure that works.

Then delete all of the following eclipse file: .project, .classpath and .settings, choose Import as Maven Project and try again, make sure eclipse uses the same maven and the same settings.xml as the command line.

If the problem remains, try to add a ServletContextListenerat the very beginning of your web.xml, and print out the locations of some of the classes involved:

System.out.println("All locations of missing class WicketApplication: " + getClass().getclassLoader().getResources("com/plop2/plop3/presentation/WicketApplication.class") );

System.out.println("Currently used version of WicketApplication: " + getClass().getclassLoader().getResource("com/plop2/plop3/presentation/WicketApplication.class") );

There are two explanations for the class not found exception: either the class is not on the classpath (because the jar is not there or due to eclipse classpath problems), or the class is there but it's not visible by the class that needs it, as the class that needs it is in a server classloader.

Also check JHades, a tool I wrote to help diagnose classpath problems.