Referencing an External Spring Application
- Procedure
- Import the external Spring application into the workspace as a plug-in project.
- Create a new plug-in project using the .
- In the JAR selection screen, click Add External and select the external Spring application JAR file.
- Enter the plug-in properties and clear the Unzip the JAR archives into the project checkbox.
- Edit the external Spring application to export the packages referenced by the Spring component implementation.
- Expand the META-INF directory of the external Spring application plug-in project.
- Double-click MANIFEST.MF.
- In the Manifest editor, click the Runtime tab.
- In the Exported Packages area, click Add and select the Show non Java Packages checkbox.
- Select the library JAR file and click OK to add it.
- Configure dependencies as described in Configuring Dependencies on External Java Classes.
- Edit the Spring Bean configuration file:
- Add the
import
statement to the bean definition that points to the location of the external Spring application configuration file:<import resource="classpath:/location_of_external_springbean.xml">
- Add the property tags from the external Spring application to the bean definition:
<property name="propertyName" ref="BeanId_External">
- Add the
- Edit the Spring component's implementation class to delegate calls to the external Spring application's classes.
The following example illustrates how to delegate calls from class HelloWorldPTImpl to the external Spring class MyLegacyJavaClass:
public class HelloWorldPTImpl extends AbstractHelloWorldPTImpl { /** * Initialization of ReuseLegacySpringComponent component. */ private MyLegacyJavaClass legacyBean; public void init() { // Component initialization code. // All properties are initialized and references are injected. if(this.legacyBean !=null){ System.out.println( "Legacy Bean Initilized..."); System.out.println( this.legacyBean.sayHello("World")); } else { throw new IllegalStateException("Injected bean is null"); } } /** * Disposal of ReuseLegacySpringComponent component. */ @Destroy public void destroy() { // Component disposal code. // All properties are disposed. } /** * Implementation of the WSDL operation: sayHello */ public HelloResponseDocument sayHello(HelloRequestDocument firstName) { HelloResponseDocument hrd=HelloResponseDocument.Factory.newInstance(); hrd.setHelloResponse(getLegacyBean().sayHello( firstName.getHelloRequest()).toString()); return hrd; } public MyLegacyJavaClass getLegacyBean() { return legacyBean; } public void setLegacyBean(MyLegacyJavaClass legacyBean) { this.legacyBean = legacyBean; } }