Java Reference
In-Depth Information
<bean id="courseDao"
<property name="entityManagerFactory" ref="entityManagerFactory" />
Now you can test this JpaCourseDao instance with the Main class by retrieving it from the Spring IoC
package com.apress.springenterpriserecipes.course;
import org.springframework.context.ApplicationContext;
public class Main {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext(" beans-jpa.xml");
CourseDao courseDao = (CourseDao) context.getBean("courseDao");
In a Java EE environment, you can look up an entity manager factory from a Java EE container with
JNDI. In Spring, you can perform a JNDI lookup by using the <jee:jndi-lookup> element.
<jee:jndi-lookup id="entityManagerFactory" jndi-name="jpa/coursePU" />
LocalEntityManagerFactoryBean creates an entity manager factory by loading the JPA configuration
file (i.e., persistence.xml ). Spring supports a more flexible way to create an entity manager factory by
another factory bean, LocalContainerEntityManagerFactoryBean . It allows you to override some of the
configurations in the JPA configuration file, such as the data source and database dialect. So, you can
take advantage of Spring's data access facilities to configure the entity manager factory.
<beans ...>
<bean id="dataSource"
<property name="driverClassName"
value="org.apache.derby.jdbc.ClientDriver" />
<property name="url"
value="jdbc: derby://localhost:1527/course; create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
Search WWH ::

Custom Search