Spring 需要AnnotationConfiguration实例才能使用

Spring 需要AnnotationConfiguration实例才能使用,spring,hibernate,spring-mvc,Spring,Hibernate,Spring Mvc,下面是正在注入sessionFactory的EmployeeDaoImpl文件 @存储库 公共类EmployeeDaoImpl实现EmployeeDao{ @Autowired private SessionFactory sessionFactory; @Override public void addEmployee(TestEmployee employee) { this.sessionFactory.getCurrentSession().save(employe

下面是正在注入sessionFactory的EmployeeDaoImpl文件

@存储库 公共类EmployeeDaoImpl实现EmployeeDao{

@Autowired
    private SessionFactory sessionFactory; 

@Override
public void addEmployee(TestEmployee employee) { 
    this.sessionFactory.getCurrentSession().save(employee); 
} 

@SuppressWarnings("unchecked") 
@Override
public List<TestEmployee> getAllEmployees() { 
    return this.sessionFactory.getCurrentSession().createQuery("from TestEmployee").list(); 
} 

@Override
public void deleteEmployee(Integer employeeId) { 
    TestEmployee employee = (TestEmployee) sessionFactory.getCurrentSession().load( 
            TestEmployee.class, employeeId); 
    if (null != employee) { 
        this.sessionFactory.getCurrentSession().delete(employee); 
    } 
} 
}

下面是我的雇员servlet文件

  <?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
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.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
    http://www.springframework.org/schema/util         http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

<context:annotation-config /> 
<context:component-scan base-package="com.rights.controller" /> 
<mvc:annotation-driven />


<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/WEB-INF/view/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:messages" /> 
    <property name="defaultEncoding" value="UTF-8" /> 
</bean> 
<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="/WEB-INF/jdbc.properties" /> 

<bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
    p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
    p:password="${jdbc.password}" /> 


<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation"> 
        <value>classpath:hibernate.cfg.xml</value> 
    </property> 
    <property name="hibernateProperties"> 
        <props> 
            <prop key="hibernate.dialect">${jdbc.dialect}</prop> 
            <prop key="hibernate.show_sql">true</prop> 
        </props> 
    </property> 
</bean> 

<bean id="employeeDAO" class="com.rights.dao.EmployeeDaoImpl"></bean> 
<bean id="employeeManager" class="com.rights.services.EmployeeManagerImpl"></bean> 

<tx:annotation-driven transaction-manager="transactionManager"/> 
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

</beans>
我得到一个AnnotationConfiguration实例是必需的错误。我已经在网上搜索过了,但无法解决这个问题。我有运行配置。我正在使用Hibernate3和Spring3.1JAR。请帮忙

<context:component-scan base-package="com.rights.controller" />
您似乎忘记了存储库的软件包,您应该使用以下方法添加它:

<context:component-scan base-package="com.rights.controller com.rights.dao" />
在您发布的配置中,如果组件扫描中未包含带有annotation@Repository的类,则spring可能不会对其进行后期处理


我希望它能帮助你

我自己解决了这个问题。。。刚刚在employee servlet文件的hibernate属性上方添加了org.hibernate.cfg.AnnotationConfiguration。