WebSphere 7中带有Spring的依赖项注入(JSR 330批注)不起作用 [英] Dependency injection with Spring (JSR 330 annotations) in WebSphere 7 is not working

查看:105
本文介绍了WebSphere 7中带有Spring的依赖项注入(JSR 330批注)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Java 6,Spring Framework 3.1.2和Mule-ESB 3.3.0构建的企业应用程序,以及与此问题无关的其他库.

I have an enterprise application built with Java 6, Spring Framework 3.1.2 and Mule-ESB 3.3.0, among other libraries not related to this question.

我们的bean和服务都用@Named@Inject JSR-330注释声明,分别用于自动组件扫描和依赖项注入(没有EJB,只有服务bean).当部署到JBoss 4.2.3(我们的测试环境)中时,一切正常.但是,当部署到WebSphere 7中时,JSR-330批注似乎无法正常工作.标记为@Named的bean根本不会被检测到.

Our beans and services are all declared with @Named and @Inject JSR-330 annotations, respectively for automatic component scanning and for dependency injection (no EJBs, only service beans). When deployed into JBoss 4.2.3 (our test environment) everything works fine. However, when deployed into WebSphere 7, the JSR-330 annotations seem not to be working. The beans marked with @Named are just not detected, at all.

我可以确保所有配置都正确(因为它在JBoss中正常工作).具体来说,<context:component-scan />具有正确定义的base-package属性,并且已正确配置scope-resolver属性以使用Jsr330ScopeMetadataResolver(我们也尝试了不使用它).

I can assure everything is configured right (since it is working in JBoss). Specifically, the <context:component-scan /> has the base-package attribute correctly defined and the scope-resolver attribute correctly configured to use Jsr330ScopeMetadataResolver (we tried without it too).

我知道WebSphere 7(7.0.0.23)可能不支持这种注释.我还没有使用@Component@Autowired Spring等效项对其进行测试.不幸的是,我们非常想使用JSR 330注释,因此即使我们在后台使用Spring Framework,我们的类也不会直接依赖于Spring.

I am aware WebSphere 7 (7.0.0.23) may not support such kind of annotations. I am yet to test it with @Component and @Autowired Spring equivalents. Unfortunately, we would very much like to use JSR 330 annotations so our classes wouldn't directly depend on Spring, even though we're using Spring Framework under the hood.

尽管如此,尽管我花了整整一天的时间来寻找一个明确的声明,说WebSphere 7不支持JSR 330批注,但到目前为止我还没有发现任何东西.

Nevertheless, although I'd spent one full work's day looking for a definite statement that WebSphere 7 does not support JSR 330 annotations, I haven't found anything so far.

此外,我不知道为什么它不起作用,因为我假设Spring Framework是通过application-context.xml文件中的<context:component-scan />指令来完成所有工作的代码.

Further, I can't see why it would not work, since I'm assuming Spring Framework is the one doing all the work, through the <context:component-scan /> directive in the application-context.xml file.

任何人都可以弄清楚这个问题吗?

Can anyone bring some light into this issue?

是否有一种方法可以通过WebSphere 7中的注释来激活依赖项注入?

Is there a way to activate dependency injection via annotations in WebSphere 7?

如果我从JSR 330 @Named/@Inject批注切换回Spring自己的@Component@Autowired,那可能行得通吗?

If I switch back from the JSR 330 @Named / @Inject annotations to Spring's own @Component and @Autowired is it likely to work?

我不顾一切地尝试,可以扩展Spring的ComponentScanBeanDefinitionParser以便它甚至在WebSphere 7中也能检测到JSR 330注释吗?

In a desperate attempt, can I extend Spring's ComponentScanBeanDefinitionParser so it will detect JSR 330 annotations even in WebSphere 7?

如果没有任何效果,我最终将退回到纯XML配置.但是,这是非常不希望的,因为将有数百个要在XML中手动配置的bean.

If nothing works, I will eventually fall back to plain XML configuration. That is highly undesirable, however, because there will be hundreds of beans to be manually configured in the XML.

推荐答案

WebSphere 8似乎是使用的正确版本.它支持EE6(WebSphere 7是EE5),而后者又包含CDI 1.0(因此为JSR 299).

WebSphere 8 seems to be the correct version to use; it supports EE6 (WebSphere 7 is EE5), which in turn contains CDI 1.0 (hence JSR 299).

下面是 DeveloperWorks 的摘录,其中总结了WebSphere版本,JSR 299和JSR 300

Below is a snippet from DeveloperWorks that summarises relationship between WebSphere versions, JSR 299 and JSR 300

依赖注入是一种已浮出水面的技术 在进入Java EE世界之前,已经实现了很多次. Spring框架和Google Guice库很受欢迎 实现.在JSR 330中,试图将这些内容包括在内. J2SE平台的功能. JSR 299是一个规范, 使用了JSR 330中定义的API,并向其中添加了更多功能 支持Java EE需求. IBM WebSphere Application Server V8和V8.5 (非自由配置文件)是完全兼容的Java EE 6容器, 实施JSR 299 .

Dependency injection is a technology that has surfaced in various implementations many times before making it into the Java EE world. The Spring Framework and the Google Guice library are popular implementations. In JSR 330, an attempt was made to include these capabilities into the J2SE platform. JSR 299 is a specification that used the APIs defined in JSR 330 and added more capabilities to support Java EE needs. IBM WebSphere Application Server V8 and V8.5 (non-Liberty profiles) are fully compliant Java EE 6 containers and implement JSR 299.

这篇关于WebSphere 7中带有Spring的依赖项注入(JSR 330批注)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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