java - Can I use specific method for dependency injection in ejb? -
for example have class gets dependecy in constructor, like
class exampleservice() { private dependency dep; public exampleservice(dependency dep) { this.dep = dep; } }
and dependecy class:
class dependency { public static dependency getinstance() { return new dependency(); } private dependency() { /*constructor implementation here*/ } }
i want inject result of dependency.getinstance() method exampleservice constructor @inject ejb annotation. possible? how? thankyou.
in cdi producer method can static, using example, following work fine:
class exampleservice() { private dependency dep; @inject public exampleservice(dependency dep) { this.dep = dep; } } class dependency { @produces public static dependency getinstance() { return new dependency(); } private dependency() { /*constructor implementation here*/ } }
however, mentioned in comments question, there might better ways depending on want.
Comments
Post a Comment