alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (applicationContext-jpa.xml)

This example Spring Framework source code file (applicationContext-jpa.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

datasource, definitions, drivermanagerdatasource, entitymanagerfactory, entitymanagerfactory, jpa, jpa, note, persistencecontext, persistenceexceptions, persistenceexceptions, see, see, spring's

The Spring Framework applicationContext-jpa.xml source code

<?xml version="1.0" encoding="UTF-8"?>
<!--
	Application context definition for PetClinic on JPA.
-->
<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:aop="http://www.springframework.org/schema/aop"
		xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xsi:schemaLocation="
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

	<!-- ========================= RESOURCE DEFINITIONS ========================= -->

	<!--
		Activates a load-time weaver for the context. Any bean within the context that
		implements LoadTimeWeaverAware (such as LocalContainerEntityManagerFactoryBean)
		will receive a reference to the autodetected load-time weaver.
	-->
	<context:load-time-weaver/>

	<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
	<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
	<context:property-placeholder location="classpath:jdbc.properties"/>

	<!-- DriverManagerDataSource is a local DataSource that works in any environment. -->
	<!-- Note that DriverManagerDataSource does not pool connections and is therefore not intended for production. -->
	<!-- See applicationContext-jdbc.xml for an example of using Commons DBCP BasicDataSource as an alternative. -->
	<!-- See the Image Database sample application for an example of using C3P0 ComboPooledDataSource as alternative. -->
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
			p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
			p:password="${jdbc.password}"/>

	<!-- JNDI DataSource for JEE environments -->
	<!--
	<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/petclinic"/>
	-->

	<!-- JPA EntityManagerFactory -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
			p:dataSource-ref="dataSource">
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"
					p:databasePlatform="${jpa.databasePlatform}" p:showSql="${jpa.showSql}"/>
			<!--
			<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"
					p:database="${jpa.database}" p:showSql="${jpa.showSql}"/>
			-->
			<!--
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
					p:database="${jpa.database}" p:showSql="${jpa.showSql}"/>
			-->
		</property>
	</bean>

	<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
			p:entityManagerFactory-ref="entityManagerFactory"/>


	<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

	<!--
		Activates various annotations to be detected in bean classes: Spring's
		@Required and @Autowired, as well as JSR 250's @PostConstruct,
		@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
		and @PersistenceUnit (if available).
	-->
	<context:annotation-config/>

	<!--
		Instruct Spring to perform declarative transaction management
		automatically on annotated classes.
	-->
	<tx:annotation-driven mode="aspectj"/>

	<!--
		Simply defining this bean will cause requests to owner names to be saved.
		This aspect is defined in petclinic.jar's META-INF/aop.xml file.
		Note that we can dependency inject this bean like any other bean.
	-->
	<bean class="org.springframework.samples.petclinic.aspects.UsageLogAspect" p:historySize="300"/>

	<!--
		Post-processor to perform exception translation on @Repository classes (from native
		exceptions such as JPA PersistenceExceptions to Spring's DataAccessException hierarchy).
	-->
	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

	<!--
		Will automatically be transactional due to @Transactional.
		EntityManager will be auto-injected due to @PersistenceContext.
		PersistenceExceptions will be auto-translated due to @Repository.
	-->
	<bean id="clinic" class="org.springframework.samples.petclinic.jpa.EntityManagerClinic"/>

</beans>

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework applicationContext-jpa.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.