Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (79 sloc) 4.01 KB
<?xml version="1.0" encoding="UTF-8"?>
<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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- It allow @Component, @Service, @Controller, etc.. annotations -->
<context:component-scan base-package="com.waheed.spring.hibernate" />
<!-- It allow us to use @Autowire, @Required and @Qualifier annotations -->
<context:annotation-config />
<!-- Will give access to Employee database -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/Employee" />
<property name="user" value="root" />
<property name="password" value="root123" />
<property name="minPoolSize" value="8" />
<property name="maxPoolSize" value="16" />
<property name="maxIdleTime" value="3600" />
</bean>
<!-- This datasource will create the Employee db if not exist -->
<bean id="createDBSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" depends-on="createDB"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306" />
<property name="user" value="root" />
<property name="password" value="root123" />
<property name="minPoolSize" value="8" />
<property name="maxPoolSize" value="16" />
<property name="maxIdleTime" value="3600" />
</bean>
<bean id="operation" class="com.waheed.spring.hibernate.Operation" />
<!-- Updater is used to automatically update DB schema upon startup if Employee version has changed -->
<bean id="LiquibaseUpdater" class="liquibase.integration.spring.SpringLiquibase" depends-on="createDB">
<property name="dataSource" ref="dataSource" />
<property name="changeLog" value="classpath:db-changelog.xml" />
</bean>
<bean id="createDB" class="com.waheed.spring.hibernate.CreateDB">
<property name="dbName" value="Employee"/>
<property name="dataSource" ref="createDBSource"></property>
</bean>
<!-- Needed here to make sure Liquibase updater runs prior to DAO's startup -->
<bean class="com.waheed.spring.hibernate.DaoImpl" id="dao"
depends-on="LiquibaseUpdater">
</bean>
<!-- Session factory required to access internal Employee database -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" depends-on="createDB">
<!-- Session factory required to access internal TM database -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.waheed.spring.hibernate.Employee</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<!-- Main transaction manager for accessing internal DB -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>