spring - WebSphere 7 中的 Spring 依赖注入(inject)(JSR 330 注释)不起作用

标签 spring dependency-injection websphere code-injection jsr330

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

我们的bean和服务均以 @Named 声明和@Inject JSR-330 注释,分别用于自动组件扫描和依赖项注入(inject)(没有 EJB,只有服务 bean)。当部署到 JBoss 4.2.3(我们的测试环境)中时,一切正常。然而,当部署到 WebSphere 7 中时,JSR-330 注释似乎不起作用。标有@Named的 bean 只是根本没有被检测到。

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

我知道WebSphere 7 (7.0.0.23) 可能不支持此类注释。我还没有用 @Component 来测试它和@Autowired Spring 等效物。不幸的是,我们非常希望使用 JSR 330 注释,这样我们的类就不会直接依赖于 Spring,即使我们在底层使用 Spring 框架。

尽管如此,尽管我花了一整天的时间寻找 WebSphere 7 不支持 JSR 330 注释的明确声明,但到目前为止我还没有找到任何内容。

此外,我不明白为什么它不起作用,因为我假设 Spring 框架是通过 <context:component-scan /> 完成所有工作的框架。 application-context.xml 中的指令文件。

任何人都可以阐明这个问题吗?

有没有办法在 WebSphere 7 中通过注释激活依赖注入(inject)?

如果我从 JSR 330 切换回来 @Named/@Inject Spring自己的注解@Component@Autowired它可能有效吗?

在绝望的尝试中,我可以延长Spring的ComponentScanBeanDefinitionParser吗?所以即使在 WebSphere 7 中它也会检测 JSR 330 注释?

如果没有任何效果,我最终将退回到纯 XML 配置。然而,这是非常不可取的,因为将有数百个 bean 需要在 XML 中手动配置。

最佳答案

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

以下是 DeveloperWorks 的片段总结了 WebSphere 版本、JSR 299 和 JSR 300 之间的关系

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.

关于spring - WebSphere 7 中的 Spring 依赖注入(inject)(JSR 330 注释)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14708725/

相关文章:

Websphere MQ 服务器配置

java - 为java创建WebSphere管理客户端程序

java - 当需要来自多个表的字段时,如何避免在 JPA 中使用 Hibernate 加入 'explosions'?

java - Mapsruct 类和 @Service 类没有 @Autowired

Angular 将不同的服务实现注入(inject)子模块

java - 是否可以同时@inject guice ctor和成员?

android - dagger2 注入(inject)不起作用 - SharedPreferences

json - 如何在 Spring 中包装 JSON 响应

java - 事务中选择。如何将过程更改包含到这些 SELECT 中?

java - Websphere 中的 Eclipse Scout RAP UI 部署