简体   繁体   English

Java-在内部注入Bean方法

[英]Java - Inject Bean inside method

I want to inject bean inside my method. 我想在我的方法中注入bean。 I have remote method(Direct Web Remoting) and i need to inject some bean inside this method. 我有远程方法(直接Web远程处理),我需要在此方法中注入一些bean。 I can't use @Inject annotation in field declaration section because it will not work. 我无法在字段声明部分中使用@Inject注释,因为它将无法工作。 It is even possible ? 可能吗?

It could be possible using serious bytecode instrumentation, but that's probably not feasible. 使用严肃的字节码检测可能是可行的,但这可能不可行。

Does DWR prevent you from using regular Injection? DWR是否会阻止您使用常规注射?

There are lots of ways to do something like this. 有很多方法可以执行这样的操作。 What container do you run? 您运行什么容器? DWR doesn't seem to support CDI yet. DWR似乎还不支持CDI。

Apache DeltaSpike has a way you can manually inject beans. Apache DeltaSpike提供了一种可以手动注入bean的方法。 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 . 看看BeanManager中的getBeans。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM