java - How to disable spring destruction callback on object returned from controller -


edit: turned out else in configuration

whenever return object inferable destruction method rest controller, returned object gets closed, possible disable this?

for example if have object this:

public class myobject implements autocloseable {    // json   private @jsonvalue string foo = "hello world";    public void close () throws exception {     system.out.println ("close()");     new throwable ("stack trace").printstacktrace (system.out);   } } 

and controller this:

@controller public class mycontroller {    private map<string, myobject> objects = new hashmap<> ();    @postconstruct   private void populate () {     objects.put ("one", new myobject ());     objects.put ("two", new myobject ());   }    @requestmapping ("/hello/{id}")   @responsebody   public myobject test (@pathvariable ("id") string id) {     return objects.get (id);   } } 

spring call myobject.close() after returned controller method. not spring managed object , i'd disable closing it, syntactically @ controller method site, possible?

this spring 3.2 , 4.0, googling around believe doesn't happen in 3.1.

edit: posting stack trace, final cleanup() method has @predestroy annotation on it, same thing happens if implement autocloseable. objects of simpledataset class not managed spring.

java.lang.throwable: stack trace     @ edu.dfci.cccb.mev.dataset.domain.simple.simpledataset.cleanup(simpledataset.java:106)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:601)     @ org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor$lifecycleelement.invoke(initdestroyannotationbeanpostprocessor.java:349)     @ org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor$lifecyclemetadata.invokedestroymethods(initdestroyannotationbeanpostprocessor.java:314)     @ org.springframework.beans.factory.annotation.initdestroyannotationbeanpostprocessor.postprocessbeforedestruction(initdestroyannotationbeanpostprocessor.java:153)     @ org.springframework.beans.factory.support.disposablebeanadapter.destroy(disposablebeanadapter.java:238)     @ org.springframework.beans.factory.support.disposablebeanadapter.run(disposablebeanadapter.java:231)     @ org.springframework.web.context.request.abstractrequestattributes.executerequestdestructioncallbacks(abstractrequestattributes.java:91)     @ org.springframework.web.context.request.abstractrequestattributes.requestcompleted(abstractrequestattributes.java:47)     @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:949)     @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:822)     @ javax.servlet.http.httpservlet.service(httpservlet.java:735)     @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:807)     @ javax.servlet.http.httpservlet.service(httpservlet.java:848)     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:686)     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:501)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137)     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:557)     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:231)     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1086)     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:428)     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:193)     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:1020)     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135)     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255)     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154)     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116)     @ org.eclipse.jetty.server.server.handle(server.java:370)     @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:489)     @ org.eclipse.jetty.server.abstracthttpconnection.headercomplete(abstracthttpconnection.java:949)     @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.headercomplete(abstracthttpconnection.java:1011)     @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:644)     @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:235)     @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82)     @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:668)     @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52)     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608)     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543)     @ java.lang.thread.run(thread.java:722) 

when have @responsebody annotated handler method, spring uses requestresponsebodymethodprocessor handle value returned.

this done in servletinvocablehandlermethod#invokeandhandler(..) implemented such

public final void invokeandhandle(servletwebrequest webrequest,         modelandviewcontainer mavcontainer, object... providedargs) throws exception {      object returnvalue = invokeforrequest(webrequest, mavcontainer, providedargs);      setresponsestatus(webrequest);      if (returnvalue == null) {         if (isrequestnotmodified(webrequest) || hasresponsestatus() || mavcontainer.isrequesthandled()) {             mavcontainer.setrequesthandled(true);             return;         }     }     else if (stringutils.hastext(this.responsereason)) {         mavcontainer.setrequesthandled(true);         return;     }      mavcontainer.setrequesthandled(false);      try {         this.returnvaluehandlers.handlereturnvalue(returnvalue, getreturnvaluetype(returnvalue), mavcontainer, webrequest);     }     catch (exception ex) {         if (logger.istraceenabled()) {             logger.trace(getreturnvaluehandlingerrormessage("error handling return value", returnvalue), ex);         }         throw ex;     } } 

where

this.returnvaluehandlers.handlereturnvalue(returnvalue, getreturnvaluetype(returnvalue), mavcontainer, webrequest); 

delegates requestresponsebodymethodprocessor. nothing in here calls close() on return value.

what describing not possible default. must have else in configuration.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -