我的應用程序無法autowire entityManagerFactory。@Autowired entityManagerFactory爲空
我的applicationContext.xml:
<tx:annotation-driven/>
<context:component-scan base-package="top.level.package" />
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocation">
<value>classpath:jpa-persistence.xml</value>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
我java類:
@Component
public class Engine {
@Autowired
@Qualifier("entityManagerFactory")
private EntityManagerFactory entityManagerFactory;
......
}
問:
的entityManagerFactory爲何爲空?
如何獲得引擎實例? –
可能是因爲'@Qualifier(「entityManagerFactory」)'。您沒有在您的xml配置中符合emf –
@orid它通過'id'屬性。 –