简体   繁体   中英

Exception org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class

I have been struggling with this error for quite few days. I have a maven based project in eclipse. I am trying to deploy the application in Tomcat. My versions are : Java : JDK 1.7.0_55 Eclipse : Luna Maven : 3.2.1 Tomcat : 7.0.54

While maven creates the war file properly and gets deployed in standalone Tomcat successfully. The same does not work while I try to publish it within Eclipse.

I receive the following error.

SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.test.testhr.dao.EmployeeDAO] for bean with name 'employeeDAO' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.test.testhr.dao.EmployeeDAO
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:959)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:683)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframewor

My web.xml looks like below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <context-param>  
        <param-name>primefaces.THEME</param-name>  
        <param-value>aristo</param-value>  
    </context-param> 
    <servlet>
        <servlet-name>FacesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>FacesServlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <filter>
        <filter-name>AuthenticationFilter</filter-name>
        <filter-class>com.test.testhr.core.ui.servlet.AuthenticationFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>AuthenticationFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

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

</web-app>

My applicationContext.xml looks like below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/tx                        
                        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="loadTimeWeaver">
            <bean
                class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
        </property>
        <property name="persistenceXmlLocation" value="WEB-INF/persistence.xml" />
        <property name="persistenceUnitName" value="myUnit" />
        <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="showSql">true</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="false" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="dataSource" ref="dataSource" />
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@//localhost:1521/orclktlt" />
        <property name="username" value="testhr" />
        <property name="password" value="testhr" />
    </bean>

    <context:component-scan base-package="com" />

    <!-- Declare DAO -->
    <bean id="genericDAO" class="com.test.testhr.dao.GenericDAO"
        abstract="true" />
    <bean id="employeeDAO" class="com.test.testhr.dao.EmployeeDAO"
        parent="genericDAO" />
    <bean id="userDAO" class=" com.test.testhr.dao.UserDAO" parent="genericDAO" />
    <bean id="departmentDAO" class=" com.test.testhr.dao.DepartmentDAO"
        parent="genericDAO" />
    <bean id="streamDAO" class="com.test.testhr.dao.StreamDAO"
        parent="genericDAO" />
    <bean id="lookupCodeDAO" class="com.test.testhr.dao.LookupCodeDAO"
        parent="genericDAO" />



    <!-- Declare Services -->
    <bean id="employeeService" class="com.test.testhr.service.employee.EmployeeService">
        <!-- <property name="employeeDAO" ref="employeeDAO" /> -->
    </bean>
    <bean id="logInService" class="com.test.testhr.service.authentication.LogInService" />
    <bean id="departmentService" class="com.test.testhr.service.settings.DepartmentService">
        <!-- <property name="departmentDAO" ref="departmentDAO" /> -->
    </bean>
    <bean id="streamService" class="com.test.testhr.service.settings.StreamService">
        <!-- <property name="streamDAO" ref="streamDAO" /> -->
    </bean>
    <bean id="lookupCodeService" class="com.test.testhr.service.settings.LookupCodeService">
        <!-- <property name="lookupCodeDAO" ref="lookupCodeDAO" /> -->
    </bean>

    <bean id="userService" class="com.test.testhr.service.user.UserService">
        <!-- <property name="userDAO" ref="userDAO" /> -->
    </bean>

    <!-- Other utility classes -->

    <!-- <bean id="lookupCodeCacheUtil" class="com.test.testhr.cache.util.LookupCodeCacheUtil"/> -->
    <!-- <bean id="variableContext" class="com.test.testhr.system.VariableContext" 
        scope="prototype" /> -->

    <!-- Security configuration -->
    <!-- <bean id="abstractEncrypptor" class="com.test.testhr.security.encryption.AbstractEncrypptor" 
        abstract="true"> -->
    <!-- <property name="password" value="test" /> -->
    <!-- <property name="pswdIterations" value="65536" /> -->
    <!-- <property name="keySize" value="256" /> -->
    <!-- </bean> -->
</beans>    

Can someone help?

Because:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.test.testhr.dao.EmployeeDAO]

means that the com.test.testhr.dao.EmployeeDAO.class can't be found, have you checked that such class doesn't exists inside the war generated by your IDE Maven plugin?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM