1
我有一個類,它看起來是這樣的..NoSuchBeanDefinitionException - 沒有名爲blPU bean被定義 - 不能注入的EntityManager JPA
@Repository("myService")
@Transactional
public class MyDaoImpl implements MyDao
{
@PersistenceContext(unitName="blPU")
protected EntityManager em;
@Resource(name="blEntityConfiguration")
protected EntityConfiguration entityConfiguration;
@Override
@Transactional
public Person findPersonByUsername(String username)
{
System.out.println("The entity manager is "+em);
// ....
}
}
和位於src/main/resources/META-INF/persistence.xml
<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/web</non-jta-data-source>
<class>com.mycompany.dao.MyDaoImpl</class>
<exclude-unlisted-classes/>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.hbm2ddl.import_files" value="/sql/import_storage.sql"/>
</properties>
</persistence-unit>
的persistence.xml
但我收到以下錯誤..
[artifact:mvn] org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'blPU' is defined
[artifact:mvn] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
這個jta的數據源聲明如下。
<Resource name="jdbc/web"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
timeBetweenEvictionRunsMillis="30000"
maxActive="15"
maxIdle="10"
minIdle="5"
removeAbandonedTimeout="60"
removeAbandoned="false"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="${database.user}"
password="${database.password}"
driverClassName="${database.driver}"
url="${database.url}"/>
了有益的意見,你可以發佈你的Spring配置,特別是部分在實體管理器工廠創建? – geoand
實體管理器工廠是容器管理的。它使用JNDI – user12458
數據源是容器管理的,而不是實體管理器工廠。你的Spring配置中沒有'LocalEntityManagerFactoryBean'類型的bean嗎?如果沒有,那就是問題 – geoand