Creating the springinit.java file, Creating the, Springinit – HP Integrity NonStop H-Series User Manual
Page 417: Java file

1.
2.
3.
Modifying the applicationContext.xml File
4.
5.
Creating the
SpringInit
.java File
Create a Java class (
SpringInit.java
) to initialize the EmpInfo application context when the
application is exposed under Axis2/Java.
NOTE:
The
SpringInit.java
is a
ServiceLifeCycle
class and its startUp method gets
called when it is being loaded. This is required to expose EmpInfo as a webservice under
Axis2/Java.
To create
SpringInit.java
, complete the following steps:
1.
Create
SpringInit.java
in the
com.hp.empinfo.service
package, as explained in
Creating the Controller for EmpInfo
section in
chapter.
2.
Modify the
SpringInit.java
file to include the startUp method.
After modification, the
SpringInit.java
file must appear as:
package com.hp.empinfo.service;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.engine.ServiceLifeCycle;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.description.AxisService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SpringInit implements ServiceLifeCycle {
private static Log logger = LogFactory
.getLog(SpringInit .class);
// The web service
public OMElement springInit(OMElement ignore) {
return null;
}
public void init(ServiceContext serviceContext) {
}
public void setOperationContext(OperationContext arg0) {
}
public void destroy(ServiceContext arg0) {
}
/**
* this will be called during the deployement time of the service. irrespective
* of the service scope this method will be called
*/
public void startUp(ConfigurationContext ignore, AxisService service) {
ClassLoader classLoader = service.getClassLoader();
ClassPathXmlApplicationContext appCtx = new
ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}, false);
appCtx.setClassLoader(classLoader);
appCtx.refresh();
if (logger.isDebugEnabled()) {
logger.debug("\n\nstartUp() set spring classloader via axisService.getClassLoader() ... ");
}
}
/**
* this will be called during the deployement time of the service. irrespective
* of the service scope this method will be called
*/
public void shutDown(ConfigurationContext ignore, AxisService service) {
Example of Integrating Axis2/Java with Spring
417