<?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"
		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 ========================= -->

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

	<!--
		Spring FactoryBean that creates a DataSource using Apache Commons DBCP for connection 
		pooling. See Commons DBCP documentation for the required JAR files.  This factory bean
		can populate the data source with a schema and data scripts if configured to do so.
		
		An alternate factory bean can be created for different connection pool implementations,
		C3P0 for example.
	-->
	<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
			p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" 
			p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
			p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"/>

	<!-- 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"
			p:dataSource-ref="dataSource"/>

	<!-- 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).
	-->
	<context:annotation-config/>

	<!--
		Instruct Spring to retrieve and apply @AspectJ aspects which are defined
		as beans in this context (such as the CallMonitoringAspect below).
	-->
	<aop:aspectj-autoproxy/>

	<!--
		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.
	-->
	<tx:annotation-driven/>

	<!--
		Exporter that exposes the Clinic DAO and the CallMonitoringAspect via JMX,
		based on the @ManagedResource, @ManagedAttribute, and @ManagedOperation annotations.
	-->
	<context:mbean-export/>

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

</beans>
