U can try using singleton class on spring :
this some example :
MyService :
Code:
package net.sf.hrs.services.impl;
public class MyService
{
private static MyService instance;
private String applicationName;
public void setApplicationName(String applicationName)
{
this.applicationName = applicationName;
}
public String getApplicationName()
{
return applicationName;
}
public static MyService getInstance()
{
if (instance == null) instance = new MyService();
return instance;
}
}
applicationContext :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="test" class="net.sf.hrs.services.impl.MyService" factory-method="getInstance">
<property name="applicationName" value="test"/>
</bean>
</beans>
Your application code :
Code:
public class HelloWorld
{
public void write()
{
MyService.getInstance().getApplicationName();
}
}
Hope this can help u