简体   繁体   English

org.springframework.beans.factory.CannotLoadBeanClassException:找不到类

[英]org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class

I replaced j2ee.jar with servle-api.com from my tomcat 6.0 installation directory: And that yields the error below.我从我的 tomcat 6.0 安装目录中用 servle-api.com 替换了 j2ee.jar: 这产生了下面的错误。 I'm presently trying to figure out the cause.我目前正在尝试找出原因。 What might the problem be.可能是什么问题。

I have a the bean defined in a configuration file: Sempedia-service.xml as follows我在配置文件中定义了一个 bean: Sempedia-service.xml 如下

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <bean id="sempediaSearchService"
        class="com.service.SempediaSearchManager" />


</beans>

my web.xml specifies the following beans:我的web.xml指定了以下 bean:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/Sempedia-service.xml,/WEB-INF/Sempedia-persistence.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Stack Trace堆栈跟踪

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.service.SempediaSearchManager] for bean with name 'sempediaSearchService' defined in ServletContext resource [/WEB-INF/Sempedia-service.xml]; nested exception is java.lang.ClassNotFoundException: com.service.SempediaSearchManager
    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:3934)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    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.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.ClassNotFoundException: com.service.SempediaSearchManager
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    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)
    ... 24 more

The problem is that there is no class called com.service.SempediaSearchManager on your webapp's classpath.问题是在您的 web 应用程序的类路径上没有名为com.service.SempediaSearchManager的类。 The most likely root causes are:最可能的根本原因是:

  • the fully qualified classname is incorrect in /WEB-INF/Sempedia-service.xml ; /WEB-INF/Sempedia-service.xml的完全限定类名不正确; ie the class name is something else,即类名是别的东西,

  • the class is not in your webapp's /WEB-INF/classes directory tree or a JAR file in the /WEB-INF/lib directory.该类不在您的 web 应用程序的/WEB-INF/classes目录树或/WEB-INF/lib目录中的 JAR 文件中。

EDIT : The only other thing that I can think of is that the ClassDefNotFoundException may actually be a result of an earlier class loading / static initialization problem.编辑:我能想到的唯一另一件事是ClassDefNotFoundException实际上可能是早期类加载/静态初始化问题的结果。 Check your log files for the first stack trace, and look the nested exceptions, ie the "caused by" chain.检查您的日志文件中的第一个堆栈跟踪,并查看嵌套异常,即“由”链。 [If a class load fails one time and you or Spring call Class.forName() again for some reason, then Java won't actually try to load a second time. [如果类加载一次失败并且您或 Spring 出于某种原因再次调用Class.forName() ,那么 Java 实际上不会尝试第二次加载。 Instead you will get a ClassDefNotFoundException stack trace that does not explain the real cause of the original failure.]相反,您将得到一个ClassDefNotFoundException堆栈跟踪,它没有解释原始失败的真正原因。]

If you are still stumped, you should take Eclipse out of the picture.如果您仍然难倒,您应该将 Eclipse 排除在外。 Create the WAR file in the form that you are eventually going to deploy it, then from the command line:以您最终要部署的形式创建 WAR 文件,然后从命令行:

  1. manually shutdown Tomcat手动关闭Tomcat

  2. clean out your Tomcat webapp directory,清理你的Tomcat webapp目录,

  3. copy the WAR file into the webapp directory,将 WAR 文件复制到 webapp 目录中,

  4. start Tomcat.启动Tomcat。

If that doesn't solve the problem directly, look at the deployed webapp directory on Tomcat to verify that the "missing" class is in the right place.如果这样不能直接解决问题,请查看 Tomcat 上部署的 webapp 目录以验证“缺少”的类是否在正确的位置。

I got the same error and the cause was the directory:我遇到了同样的错误,原因是目录:

U:.....WEB\\WebRoot\\WEB-INF\\classes\\com\\yourcompany\\cc\\dao U:...WEB\\WebRoot\\WEB-INF\\classes\\com\\yourcompany\\cc\\dao

was corrupted(directory or file not readable or damaged).. solved with已损坏(目录或文件不可读或损坏)..已解决

  • renaming the directory WEB-INF\\classes as WEB-INF\\classes_old将目录 WEB-INF\\classes 重命名为 WEB-INF\\classes_old
  • Eclipse's Project menu--> Clean (to recreate directories) Eclipse 的 Project 菜单--> Clean(重新创建目录)
  • redeploy --> restart server.重新部署 --> 重新启动服务器。

Check your dependencies.检查您的依赖项。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SchoolApp</groupId>
  <artifactId>SchoolApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <hibernate.version>4.2.0.Final</hibernate.version>
    <mysql.connector.version>5.1.21</mysql.connector.version>
    <spring.version>3.2.2.RELEASE</spring.version>
  </properties>

  <dependencies>
    <!-- DB related dependencies -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.connector.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>javassist</groupId>
      <artifactId>javassist</artifactId>
      <version>3.12.1.GA</version>
    </dependency>
    <!-- SPRING -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- Spring Security  -->
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-core</artifactId>
      <version>3.1.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>3.1.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>3.1.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-taglibs</artifactId>
      <version>3.1.3.RELEASE</version>
    </dependency>
    <!-- CGLIB is required to process @Configuration classes -->
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>2.2.2</version>
    </dependency>
    <!-- Servlet API and JSTL -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!-- Test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test-mvc</artifactId>
      <version>1.0.0.M1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>spring-maven-milestone</id>
      <name>Spring Maven Milestone Repository</name>
      <url>http://maven.springframework.org/milestone</url>
    </repository>
  </repositories>

  <build>
    <finalName>spr-mvc-hib</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I have faced similar problem我遇到过类似的问题

So所以

I just do我只是做

1.update Maven Project 1.更新Maven项目

2.install maven. 2.安装maven。

i recently experienced this issue when i was trying to build and suddenly the laptop battery ran out of charge.我最近在尝试构建时遇到了这个问题,突然笔记本电池没电了。 I just removed all the servers from eclipse and then restore it.我刚刚从 eclipse 中删除了所有服务器,然后将其恢复。 after doing that, i re-built the war file and it worked.这样做之后,我重新构建了war文件并且它起作用了。

I have the same problem.我也有同样的问题。 I checked my /WEB-INF/classes based on Stephen's recommendation:我根据斯蒂芬的建议检查了我的 /WEB-INF/classes :

the class is not in your webapp's /WEB-INF/classes directory tree or a JAR file in the /WEB-INF/lib directory.该类不在您的 web 应用程序的 /WEB-INF/classes 目录树或 /WEB-INF/lib 目录中的 JAR 文件中。

I discovered I have an outdated jar file.我发现我有一个过时的 jar 文件。 Replacing it with the latest jar file solved the issue.用最新的 jar 文件替换它解决了这个问题。

Just leaving this here for future visitors:只是把这个留在这里给未来的访客:

In my case the /WEB-INF/classes directory was missing.在我的情况下, /WEB-INF/classes 目录丢失了。 If you are using Eclipse, make sure the .settings/org.eclipse.wst.common.component is correct (Deployment Assembly in the project settings).如果您使用的是 Eclipse,请确保 .settings/org.eclipse.wst.common.component 是正确的(项目设置中的部署程序集)。

In my case it was missing就我而言,它不见了

    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>

This file is also a common source of errors as mentioned by Anuj (missing dependencies of other projects).该文件也是 Anuj 提到的常见错误来源(缺少其他项目的依赖项)。

Otherwise, hopefully the other answers (or the "Problems" tab) will help you.否则,希望其他答案(或“问题”选项卡)会对您有所帮助。

i dont know whether it is relevant to your issue, i got similar issue which i got solved by我不知道它是否与您的问题有关,我遇到了类似的问题,我已经解决了

1) In eclipse right click server and clean 1)在eclipse中右键单击服务器并清理

if it still didnt work如果它仍然不起作用

2) export the project and delete the project create the project with same name and import the project and add the project to server and run. 2)导出项目并删除项目创建同名项目并导入项目并将项目添加到服务器并运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异常org.springframework.beans.factory.CannotLoadBeanClassException:找不到类 - Exception org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class org.springframework.beans.factory.CannotLoadBeanClassException:找不到类 - org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class org.springframework.beans.factory.CannotLoadBeanClassException:找不到类[org.springframework.orm.hibernate5.HibernateTrasactionManager] - org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate5.HibernateTrasactionManager] “ org.springframework.beans.factory.CannotLoadBeanClassException:找不到类[org.springframework.jdbc.datasource - " org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource 集成jsf和spring异常:org.springframework.beans.factory.CannotLoadBeanClassException:找不到类 - integration jsf and spring Exception : org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class org.springframework.beans.factory.CannotLoadBeanClassException:找不到名为&#39;的bean的类[com.Dao.ApplicationDaoImpl] - org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.Dao.ApplicationDaoImpl] for bean with name ' 部署到glassfish服务器时出现“ org.springframework.beans.factory.CannotLoadBeanClassException:找不到类…” - “org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class…” when deploying to glassfish server org.springframework.beans.factory.CannotLoadBeanClassException - org.springframework.beans.factory.CannotLoadBeanClassException Spring/Java org.springframework.beans.factory.CannotLoadBeanClassException: 找不到类 [C:\\launchCodeFiles\\src\\main\\java\\RunMario.java] - Spring/Java org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [C:\launchCodeFiles\src\main\java\RunMario.java] org.springframework.beans.factory.CannotLoadBeanClassException:找不到 bean 的 class [com.mchange.v2.c3p0.ComboPooledDataSource] - org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mchange.v2.c3p0.ComboPooledDataSource] for bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM