Spring初始化错误:java.lang.IncompatibleClassChangeError:实现类

时间:2015-12-11 16:43:56

标签: java spring dependency-injection liferay javabeans

我得到了这个例外,我无法弄清楚原因。 CheckoutItem和接口CheckoutItemDAO位于一个单独的jar中,并且是没有任何注释的简单javabeans。 CheckoutItemDAOHibernate实施CheckoutItemDAO

16:26:31,135 ERROR [ContextLoader:227] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'checkoutService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.newscom.dao.CheckoutItemDAO com.liferay.webform.business.CheckoutService.checkoutItemDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'checkoutItemDAO' defined in ServletContext resource [/WEB-INF/context/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/context/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class

CheckoutService.java

package com.liferay.webform.business;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.newscom.dao.CheckoutItemDAO;
import com.newscom.model.CheckoutItem;

@Service
@Transactional
@Controller
public class CheckoutService {
@Autowired private CheckoutItemDAO checkoutItemDAO;

public CheckoutItem getCheckoutItemById(Integer checkoutItemId) {
    List<CheckoutItem> items = checkoutItemDAO.retrieveRecordByID(checkoutItemId);
    if (items != null && items.size() > 0) {
        return items.get(0);
    }
    else {
        return null;
    }
}

的applicationContext.xml

<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<context:component-scan base-package="com.liferay.webform.business" />

<tx:annotation-driven/>

<util:properties id="applicationProperties" location="classpath:application.properties"/>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/ncdb"></property>
</bean>

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.newscom.model.CheckoutItem</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.cache.use_query_cache">false</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
            <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
            <prop key="hibernate.connection.release_mode">auto</prop>
            <prop key="hibernate.query.substitutions">true 1, false 0</prop>
        </props>
    </property>
</bean>

<bean id="daoTemplate" abstract="true">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean parent="daoTemplate" id="checkoutItemDAO" class="com.newscom.dao.hibernate.CheckoutItemDAOHibernate" />

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

0 个答案:

没有答案