首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >服务器启动期间Tomcat、Spring、Maven和Eclipse上使用wicket的ClassNotFoundException

服务器启动期间Tomcat、Spring、Maven和Eclipse上使用wicket的ClassNotFoundException
EN

Stack Overflow用户
提问于 2014-02-27 13:59:24
回答 1查看 2.3K关注 0票数 2

在服务器启动期间,在Tomcat、Spring和Eclipse上使用wicket的ClassNotFoundException。

在Eclipse中,当我试图加载服务器时,会遇到一些错误,导致404页。

这里是stackTrace:

代码语言:javascript
复制
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

plop3-admin-provider-wicket的pom.xml:

代码语言:javascript
复制
<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>

Plop3-admin-war的pom.xml:

代码语言:javascript
复制
<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>

plop3-admin-war的web.xml:

代码语言:javascript
复制
<!-- 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>

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

代码语言:javascript
复制
<import resource="applicationPropertiesContext.xml" />
<import resource="dependenciesInjectionContext.xml" />  
<import resource="jpaDaoContext.xml" />
<import resource="transactionContext.xml" />
<import resource="wicketContext.xml" />

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

代码语言:javascript
复制
<bean id="wicketApplication" name="wicketApplication"
    class="com.plop2.plop3.presentation.WicketApplication" scope="singleton">
</bean>

我不明白为什么不能加载类,plop3-admin-provider-wicket出现在plop3-admin-war Maven依赖项列表中。

快把我逼疯了,两天后我就在上面了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-27 23:33:52

尝试构建一个WAR并将其部署到一个完全在eclipse之外运行的tomcat,方法是将WAR放在webapp目录中并运行启动脚本。

这将确定问题是库依赖还是eclipse工作区设置中的问题。

如果怀疑工作区设置,请尝试关闭eclipse中的所有项目并从工作区中删除它们。从命令行执行一个mvn clean install,并确保其工作正常。

然后删除以下所有eclipse文件:.project.classpath.settings,选择Import as Maven Project并重试,确保eclipse使用与命令行相同的maven和相同的settings.xml。

如果问题仍然存在,尝试在ServletContextListener的开头添加一个web.xml,并打印出所涉及的一些类的位置:

代码语言:javascript
复制
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") );

对于这个类没有找到异常,有两个解释:要么类不在类路径上(因为jar不在那里,要么由于eclipse类路径问题),或者类在那里,但是需要它的类是不可见的,就像需要它的类在服务器类加载器中一样。

还可以查看JHades,这是我为帮助诊断类路径问题而编写的工具。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22070764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档