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

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

This example Spring Framework source code file (applicationContext-hibernate.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, datasource, definitions, drivermanagerdatasource, hibernate, hibernate, jmx, jmx, jndi, jndi, jta, see, sessionfactory, transaction

The Spring Framework applicationContext-hibernate.xml source code

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

	<!-- 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"/>
	-->

	<!-- Hibernate SessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
			p:dataSource-ref="dataSource" p:mappingResources="petclinic.hbm.xml">
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}
				<prop key="hibernate.show_sql">${hibernate.show_sql}
				<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}
			</props>
		</property>
		<property name="eventListeners">
			<map>
				<entry key="merge">
					<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
				</entry>
			</map>
		</property>
	</bean>

	<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
			p:sessionFactory-ref="sessionFactory"/>

	<!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
	<!--
	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
	-->


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

	<!--
		Activates various annotations to be detected in bean classes:
		Spring's @Required and @Autowired, as well as JSR 250's @Resource.
	-->
	<context:annotation-config/>

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

	<!--
		Exporter that exposes the Hibernate statistics service via JMX. Autodetects the
		service MBean, using its bean name as JMX object name.
	-->
	<context:mbean-export/>

	<!-- PetClinic's central data access object: Hibernate implementation -->
	<bean id="clinic" class="org.springframework.samples.petclinic.hibernate.HibernateClinic"/>

	<!-- Hibernate's JMX statistics service -->
	<bean name="petclinic:type=HibernateStatistics" class="org.hibernate.jmx.StatisticsService" autowire="byName"/>

</beans>

Other Spring Framework examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.