gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:20:33 26 4
gpt4 key购买 nike

服务器启动期间在 Tomcat、Spring 和 Eclipse 上出现 ClassNotFoundException 和 wicket。

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

这是堆栈跟踪:

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 :

<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:

<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:

<!-- 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 :

<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 :

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

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

这让我发疯,两天我就在这上面。

最佳答案

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

这将确定问题是出在库依赖性上还是在 eclipse 工作区设置中。

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

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

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

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,这是我编写的一个帮助工具 diagnose classpath problems .

关于java - 服务器启动期间在 Tomcat、Spring、Maven 和 Eclipse 上使用 wicket 的 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22070764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com