No unique bean of type [javax.persistence.EntityManagerFactory] is defined
I am new to Spring and am trying to go through 2 books and online help to get it set up to access the database but my page keeps giving me the above error. Can someone please help me identify what I have configured incorrectly?
The full error is:
org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0
Thank you for your help.
Ray
The datasource is defined as this:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
Index of /schema/context
http://www.springframework.org/schem...ontext-3.0.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<context:property-placeholder location="/WEB-INF/jdbc.properties" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The applicationContext is this:
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...ring-beans.xsd
Index of /schema/context
http://www.springframework.org/schem...ng-context.xsd
Index of /schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
<mvc:view-controller path="/index.html" />
<bean name="helloService" class="dvdTracker.service.HelloService" />
<bean id="dvdDao" class="dvdTracker.repository.DvdDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The DvdDaoImpl class is this:
package dvdTracker.repository;
import dvdTracker.domain.Dvd;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedPara meterJdbcTemplate;
import org.springframework.jdbc.core.simple.Parameterized RowMapper;
public class DvdDaoImpl implements DvdDao {
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
...
Re: No unique bean of type [javax.persistence.EntityManagerFactory] is defined
Re: No unique bean of type [javax.persistence.EntityManagerFactory] is defined
Quote:
Originally Posted by
DarrylBurke
I see, I missed the code tag. Thank you. Here is my post again:
I am new to Spring and am trying to go through 2 books and online help to get it set up to access the database but my page keeps giving me the above error. Can someone please help me identify what I have configured incorrectly?
The full error is:
org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0
Thank you for your help.
Ray
The datasource is defined as this:
Code:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<context:property-placeholder location="/WEB-INF/jdbc.properties" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The applicationContext is this:
Code:
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
<mvc:view-controller path="/index.html" />
<bean name="helloService" class="dvdTracker.service.HelloService" />
<bean id="dvdDao" class="dvdTracker.repository.DvdDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The DvdDaoImpl class is this:
Code:
package dvdTracker.repository;
import dvdTracker.domain.Dvd;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
public class DvdDaoImpl implements DvdDao {
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
@Override
public List<Dvd> getDvdList() {
String sql = "select idDVD, title, dvdLength from dvd";
List<Dvd> dvds = this.jdbcTemplate.query(sql, new TransactionMapper());
return dvds;
}
...
Re: No unique bean of type [javax.persistence.EntityManagerFactory] is defined
What's the full stack trace?
That error is usually the cause of another one (initialising another object), so there should be a reasonably big stack trace which would tell you what it was trying to create.
Re: No unique bean of type [javax.persistence.EntityManagerFactory] is defined
Thank you. I was copying an example from a book and mistakenly left in the JPA filter in the web.xml file. Here was the code that I needed to remove:
Code:
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
Re: No unique bean of type [javax.persistence.EntityManagerFactory] is defined
Thanks for posting your solution.