Modifying the applicationcontext.xml file – HP Integrity NonStop J-Series User Manual

Page 240

Advertising
background image

Modifying the EmpInfo application involves the following tasks:

“Modifying the applicationContext.xml File” (page 240)

“Modifying the EmployeeDao.java File” (page 241)

“Creating the Employee.hbm.xml File” (page 242)

“Removing the EmployeeRowMapper.java File” (page 245)

“Adding Dependency JAR Files” (page 246)

Modifying the applicationContext.xml File

Modify the EmpInfo/WebContent/WEB-INF/applicationContext.xml file, so that it uses
the Hibernate SessionFactory to connect to the employee SQL/MX database table using the
following steps:

1.

Specify the SessionFactory in the applicationContext.xml file as shown:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SqlmxDialect</prop>

Example of Integrating Hibernate into Spring 9

<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>

2.

Modify the bean instance of the EmployeeDao class to add the reference of the Hibernate
SessionFactory, as shown:

<bean id="empdao" class="com.hp.springapp.service.EmployeeDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

After modification, the applicationContext.xml file should appear as:

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<property name="driverClassName">
<value>${jdbc.driver}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.user}</value>

240 Integrating Frameworks

Advertising
This manual is related to the following products: