JPA的一些问题


Error creating bean with name 'mainController':

Unsatisfied dependency expressed through field 'testService':

Error creating bean with name 'testServiceImpl':

Unsatisfied dependency expressed through field 'testRepository':

No qualifying bean of type [com.wondersgroup.test.dao.testRepository]

创建的Bean找不到 ,不是因为不符合条件,大部分情况下是忘记加注解;

但是我已经加了注解了, 不存在这种情况;

开始是以为jar包的问题,通过修改jar包依然没有解决;

然后排除 

--------------------------------- 

 2天后更新: 

是配置的原因,之前的Repository是要受EntityManager管理的,所以就算是正确的,没有定义好的EntityManager依然会造成主权不明确的问题;

在这之后,补充上了关于EntityManager的东西,就可以了;

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

        <property name="packagesToScan" value="com.wondersgroup.test.entity" />

<property name="jpaVendorAdapter">

<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

</property>

<property name="jpaProperties">

            <props>

                <prop key="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</prop>

                <prop key="hibernate.connection.url">jdbc:sqlserver://{你的}:1433;databaseName=XHWSDZ</prop>

                <prop key="hibernate.connection.username">sa</prop>

                <prop key="hibernate.connection.password"></prop>

                <prop key="hibernate.c3p0.min_size">10</prop>

                <prop key="hibernate.hbm2ddl.auto">true</prop>

                <prop key="hibernate.show_sql">true</prop>

                <prop key="hibernate.format_sql">true</prop>

                <prop key="hibernate.connection.characterEncoding">UTF-8</prop>

                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

            </props>

         </property>

</bean>

    

     <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

        <property name="entityManagerFactory" ref="entityManagerFactory"/>

    </bean>


    <!-- 开启事务管理注解 -->

    <tx:annotation-driven transaction-manager="transactionManager"/>

配置文件修改为这样即可; 

因为不是标准的SpringMvc目录结构,所以也没有办法 

    

原文地址:https://www.cnblogs.com/zuopy/p/8025548.html