sNotFoundException引起的CannotLoadB

sNotFoundException引起的CannotLoadB

本文介绍了Spring Web App-由Java.lang.ClassNotFoundException引起的CannotLoadBeanClassException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了一段时间了,我已经用尽了所有可能的解决方案,因此非常感谢您的帮助.

Iv been struggling with this for a while now an I have exhausted all my possible solutions so any help is greatly appreciated.

这是一个简单的Web应用程序,用于测试在Web应用程序上运行的Springs SimpleJdbcTemplate,在部署后,我在Tomcat日志中收到以下错误消息

This is a simple web app used to test Springs SimpleJdbcTemplate running on a web app, tho when deployed i get the following error message in the Tomcat Logs

   10-Jan-2011 18:12:36 org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [example.jersey.spring.dao] for bean with name 'testDAO' defined in class path resource [ApplicationContext.xml]; nested exception is java.lang.ClassNotFoundException: example.jersey.spring.dao
 at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524)
 at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177)
 at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:758)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:422)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
 at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:525)
 at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1359)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
 at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
 at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1500)
 at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:670)
 at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:435)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:558)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Unknown Source)
Caused bmore
y: java.lang.ClassNotFoundException: example.jersey.spring.dao
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
 at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
 at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
 at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
 ... 42 10-Jan-2011 18:12:36 org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart

现在该文件位于tomcat服务器上,因为我已经手动检查了此文件.我还检查了应用程序上下文文件,引用正确.源文件夹也都在类路径上,因此这似乎也不是问题.

Now the file is on the tomcat server as I have checked this manually. I have also checked the application context file and the reference is correct . The source folders are also all on the classpath so this doesnt seem to be the issue either.

<bean id="testDAO" class="example.jersey.spring.dao">
        <property name="dataSource" ref="dataSource"/>
    </bean>

因此,这使我指向了POM文件,这可能是因为我使用的是Spring的较低版本,或者可能是缺少一些我刚接触Spring的JAR,所以我不是100%应该拥有的,但这就是我的POM中有spring依赖项.

So this has left me pointing at the POM file is it possible that I have an lesser version of spring or am perhaps missing some JARs i am new to Spring so I am not 100 percent on what i should have but this is the spring dependency in my POM.

<dependency>
       <groupId>com.sun.jersey.contribs</groupId>
       <artifactId>jersey-spring</artifactId>
       <version>${jersey-version}</version>
   </dependency>
     <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>${spring-version}</version>
      </dependency>

感谢您的帮助!

推荐答案

我敢打赌,您的类路径中没有名为example.jersey.spring.dao的类.确保仅创建现有类的bean. (这东西很可能是一个包裹)

I'd bet there is no class named example.jersey.spring.dao on your classpath. Make sure you are creating beans only of existing classes. (This thing is a package most likely)

这篇关于Spring Web App-由Java.lang.ClassNotFoundException引起的CannotLoadBeanClassException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:05