问题
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