HP Integrity NonStop J-Series User Manual

Page 124

Advertising
background image

2.

Modify the EmployeeInfo.java file as follows:

package com.hp.empinfo.service;

import com.hp.empinfo.domain.Employee;

public interface EmployeeInfo {

public Employee getEmployee(int empId);

}.

This creates the RMI service interface which you must implement as described in the subsequent
section.

Creating Implementation Class of RMI service Interface

To create an implementation class of RMI service, complete the following steps:
1.

Create a com.hp.empinfo.service package and an EmployeeInfoImpl class under
the com.hp.empinfo.service package, as described in

“Creating the Controller for

EmpInfo” (page 91)

.

2.

Modify the EmployeeInfoImpl.java class as follows:

package com.hp.empinfo.service;

import java.sql.SQLException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hp.empinfo.domain.Employee;

public class EmployeeInfoImpl implements EmployeeInfo {
private EmployeeDao empdaoBean; ;

public EmployeeDao getEmpdaoBean() {
return empdaoBean;
}
public void setEmpdaoBean(EmployeeDao empdaoBean) {
this.empdaoBean = empdaoBean;
}
public static String [] configFileNames = new String [] {"applicationContext.xml","clientContext.xml"};
private static ApplicationContext applicationContext = null;

public Employee getEmployee(int empId) {
Employee detail = null;

applicationContext = new ClassPathXmlApplicationContext(configFileNames);
EmployeeDao empDao = (EmployeeDao)applicationContext.getBean("empdao");

try {
detail = empDao.getDetail(empId);

} catch (SQLException e) {

e.printStackTrace();
}

return detail;

}
}

Modifying the applicationContext.xml file

You must modify the applicationContext.xml file to add the Spring RMI bean. To achieve
this, add the following code in the applicationContext.xml file:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>classpath:jdbc.properties</value></property>
</bean>

<bean id="empinfo" class="com.hp.empinfo.service.EmployeeInfoImpl">
<property name="empdaoBean" ref="empdao"/>
</bean>

<bean id="emp-rmi" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="empinfo"/>

124

Getting Started with Spring

Advertising
This manual is related to the following products: