Announcement Announcement Module
No announcement yet.
Singleton in web application and web service application Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Singleton in web application and web service application


    I am trying to develop a project that can be accessed by both a web application and a WS application via axis. In this project, there is an object that can cache something and should be shared by both applications as defined by the spring config file. However, the test results indicate that this object cannot be shared.

    Can anybody tell me if anything is wrong?

    Thanks in advance,


    Some related code is attached:

    Spring config file:


    <bean id="biopaxService" class="org.reactome.servlet.BioPAXExporterService" singleton="true">
    <property name="defaultDbName">
    <property name="dbUser">
    <property name="dbPwd">
    <property name="dbPort">
    <property name="converter">
    <ref bean="converter" />

    <bean id="exporterController" class="org.reactome.servlet.BioPAXExporterControll er">
    <property name="service">
    <ref bean="biopaxService" />

    WS Java code to use the service object:

    public class BioPAXExporterWSEndpoint extends ServletEndpointSupport {

    // The wrapped actual business object
    private BioPAXExporterService service;

    protected void onInit() {
    service = (BioPAXExporterService) getWebApplicationContext().getBean("biopaxService" );

    public String getBioPAXModel(Long dbID) throws Exception {
    System.out.println("Service in WS: " + service);
    Document doc = service.getBioPAXModel(dbID);
    // Need to convert doc to a String so that it can be consumed by WS client easily
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    StringWriter writer = new StringWriter();
    outputter.output(doc, writer);
    return writer.toString();


    Web application Java Code:

    public class BioPAXExporterController extends AbstractCommandController {
    // To provide actual service
    private BioPAXExporterService service;

    public BioPAXExporterController() {

    public void setService(BioPAXExporterService service) {
    this.service = service;

    protected ModelAndView handle(HttpServletRequest request,
    HttpServletResponse response,
    Object command,
    BindException errors) throws Exception {
    System.out.println("Service in servlet: " + service);
    HashMap map = new HashMap();
    BioPAXExporterCommand parameters = (BioPAXExporterCommand) command;
    Long dbID = parameters.getDbID();
    String dbName = parameters.getDbName();
    Document biopaxModel = null;
    if (dbName == null)
    biopaxModel = service.getBioPAXModel(dbID);
    biopaxModel = service.getBioPAXModel(dbName, dbID);
    return new ModelAndView("biopaxView", "biopaxModel", biopaxModel);

  • #2
    Did you encountered the solution?

    I'm trying to use a singleton too, to be added to the server-config.wsdd, as you did, I create a simple bean that extends ServletEndpointSupport and i set this bean in the server-config.wsdd, but it seems that every times I cal the wsdl generated, the onInit method is called.