'conf/ApplicationContext.xml'
Code:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:jdbc.properties</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<!--
Setup Hibernate based on config file
classpath:com/example/jsf/hibernate/example/resources/hibernate.cfg.xml and properties
defined by hibernateProperties.
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:conf/RequestHibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<ref local="hibernateProperties"/>
</property>
</bean>
<!-- <property name="hibernateProperties">-->
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<!-- <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>-->
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect </prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- This is the base definition for all Hibernate based DAOs -->
<bean id="FooRequestDAO" class="com.foo.impl.FooRequestDAO">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
'conf/DataSource-Test.xml'
Code:
<bean id="dataSource" destroy-method="close"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
'conf/DataSource-Prod.xml' (This is just an example, you'll have to configure it for your specific Websphere environment.)
Code:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>
</bean>
Now when developing locally, you can do this...
Code:
String[] paths = { "conf/ApplicationContext.xml", "conf/DataSource-Test.xml" };
ctx = new ClassPathXmlApplicationContext(paths);
dao = (FooRequestDAO) ctx.getBean("FooRequestDAO");
And when deploying into your Websphere environment...
Code:
String[] paths = { "conf/ApplicationContext.xml", "conf/DataSource-Test.xml" };
ctx = new ClassPathXmlApplicationContext(paths);
dao = (FooRequestDAO) ctx.getBean("FooRequestDAO");
There are better ways of achieving this, but this should hopefully get you started on the right path.
Cheers
Rick