java - Using an @Autowired resource with "try with resource" -


given following:

public class resourceone implements autocloseable {...} 

with instance of resourceone instantiated in (spring) xml config.

how should object (when autowired) used "try-with-resources statement", since required instantiate resource in try block?

one approach use reference (see below), isn't optimal.

public class test { @autowired resourceone test; //... public void execute() {  //...  try (resourceone localtest = test)  {    localtest.init()    localtest.readline();    //...  } } 

afaik think approach have taken seems way.

try (resourceone localtest = test)  {    localtest.init()    localtest.readline();    //...  } 

i assuming have autowired resource declared prototype scope though right.

    @bean     @scope(value="prototype", proxymode=scopedproxymode.default)     public resource1 resource1() {         return new resource1();     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -