没有定义EntityManagerFactory类型的限定bean

时间:2014-01-06 11:25:59

标签: spring hibernate spring-mvc jpa spring-data

我想创建一个通用的DAO,直到我发现已经有Spring data来阻止它。
在我使用hibernate + spring并且所有工作正常工作之前,我发现了tuto,我只是在我的配置中添加了这一行(hibernate + spring ):

    <jpa:repositories base-package="repository"/>

但我收到了这个错误:

Error creating bean with name 'loginC': Injection of resource dependencies failed
Error creating bean with name 'authRepository': Injection of persistence dependencies failed
No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined

我认为这是一个JPA问题,因为我总是使用hibernate。

我的hibernateContext.xml:

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

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>database.properties</value>
        </list>
    </property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driver}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.user}" />
    <property name="password" value="${jdbc.password}" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="entity" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <!-- <prop key="hibernate.show_sql">true</prop> -->
        </props>

    </property>
</bean>


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

我的servlet.xml

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

<mvc:resources mapping="/resources/**" location="/resources/" />  

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

<jpa:repositories base-package="repository"/>

我的存储库界面:

public interface AuthRepository extends JpaRepository<Auth, Integer> {}

我的控制器loginC

@Resource
private AuthRepository authRepository;


@Transactional
@RequestMapping(value = "welcome")
public String printWelcome() {

    authRepository.save(new Auth("spring", "data"));

    return "hello";
}

0 个答案:

没有答案