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
Post a Comment