java - Spring: calling method before injection -
java - Spring: calling method before injection -
i explain problem simple example:
class="lang-java prettyprint-override">public class () { private b b; public () { /* ... */ } public b getb () { /* ... */ } @autowired public void setb (b b) { /* ... */ } public init (int x, int y, float rx, float ry) { /* ... */ } }
and
class="lang-java prettyprint-override">public class b () { private a; public b () { /* ... */ } public geta () { /* ... */ } @autowired public void seta (a a) { /* ... */ } public init (int x, int y, float rx, float ry) { /* ... */ } }
so need phone call init()
method before injection, because after injection called method injected component in loop fps times per second, , of course of study not initialized nullpointerexception
.
i utilize setter injection , create object context.getbean("a")
.
is there way phone call method init()
before injection?
i believe you're looking @postconstruct
, specified in jsr250, tells spring run method dependencies injected bean. implement initializingbean
interface. check out this more details , options. however, circular dependency going complicate things. there few ways solve this, @ end of day you're improve off redesigning remove circular dependency.
java spring dependency-injection javabeans autowired
Comments
Post a Comment