Java - Inject Bean inside method

不问归期 提交于 2019-12-12 05:26:47

问题


I want to inject bean inside my method. I have remote method(Direct Web Remoting) and i need to inject some bean inside this method. I can't use @Inject annotation in field declaration section because it will not work. It is even possible ?


回答1:


It could be possible using serious bytecode instrumentation, but that's probably not feasible.

Does DWR prevent you from using regular Injection?




回答2:


There are lots of ways to do something like this. What container do you run? DWR doesn't seem to support CDI yet.

Apache DeltaSpike has a way you can manually inject beans. One way is to do a call like this:

EchoService echoService = BeanProvider.getContextualReference(EchoService.class, false);

Another is to enrich the actual class at runtime. Take a look at getBeans in BeanManager.



来源:https://stackoverflow.com/questions/18977050/java-inject-bean-inside-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!