Java-在内部注入Bean方法 [英] Java - Inject Bean inside method

查看:263
本文介绍了Java-在内部注入Bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的方法中注入bean。我有远程方法(直接Web远程处理),我需要在此方法中注入一些bean。我无法在字段声明部分中使用@Inject注释,因为它无法工作。甚至有可能吗?

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 ?

推荐答案

有很多方法可以执行这样的操作。您运行什么容器? DWR似乎还不支持CDI。

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提供了一种手动注入bean的方法。一种方法是进行如下调用:

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);

另一种方法是在运行时丰富实际的类。看看 BeanManager 中的getBeans。

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

这篇关于Java-在内部注入Bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆