home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

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

This example Spring Framework source code file (applicationContext-jdbc.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

commons, commons, datasource, dbcp, dbcp, jdbc, jndi, jta, jta, see, spring, spring, spring's, transaction

The Spring Framework applicationContext-jdbc.xml source code

<?xml version="1.0" encoding="UTF-8"?>
	Application context definition for PetClinic on JDBC.
<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"
			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 ========================= -->

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

		Uses Apache Commons DBCP for connection pooling. See Commons DBCP documentation
		for the required JAR files. See the PetStore sample application also shipped with
		Spring, for an example of Commons DBCP usage and the necessary build script.
		Alternatively you can use another connection pool such as C3P0, similarly configured
		using Spring.
		A standalone connection pool such as Commons DBCP is a good choice for use outside an
		application server environment, including web applications running in a web container without
		JTA, or integration testing using the org.springframework.test package.
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
			p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"

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

	<!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"

	<!-- 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 @PostConstruct,
		@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
		and @PersistenceUnit (if available).

		Instruct Spring to retrieve and apply @AspectJ aspects which are defined
		as beans in this context (such as the CallMonitoringAspect below).

		Instruct Spring to perform automatic transaction management on annotated classes.
		The SimpleJdbcClinic implementation declares @Transactional annotations.
		"proxy-target-class" is set because of SimpleJdbcClinic's @ManagedOperation usage.

		Exporter that exposes the Clinic DAO and the CallMonitoringAspect via JMX,
		based on the @ManagedResource, @ManagedAttribute, and @ManagedOperation annotations.

	<!-- PetClinic's central data access object using Spring's SimpleJdbcTemplate -->
	<bean id="clinic" class="org.springframework.samples.petclinic.jdbc.SimpleJdbcClinic"/>

	<!-- Call monitoring aspect that monitors call count and call invocation time -->
	<bean id="callMonitor" class="org.springframework.samples.petclinic.aspects.CallMonitoringAspect"/>


Other Spring Framework examples (source code examples)

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

my book on functional programming


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.