JBoss 5.1:Spring @Resource 注释不起作用 [英] JBoss 5.1: Spring @Resource annotation not working

查看:105
本文介绍了JBoss 5.1:Spring @Resource 注释不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 Spring 3 和 Hibernate 3.5 和 Java 1.6 的应用程序.

I am working on an application using Spring 3 and Hibernate 3.5 with Java 1.6.

到目前为止,我一直在使用 JBoss 4.2.1,一切都很好.

So far I've been using JBoss 4.2.1 and everything was fine.

现在在迁移到 JBoss 5.1 时,我遇到了很多问题.其中之一是 JBoss 忽略了 Spring @Resource 注释.我收到以下异常:

Now while migrating to JBoss 5.1, I encountered lot of issues. One of them is that JBoss is ignoring the Spring @Resource annotation. I get the following exception:

java.lang.RuntimeException: 部署 pol-1.0.war 的 serviceManager 需要映射名称在 org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXmlResourceEnvRefs(WebResourceHandler.java:287)在 org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXml(WebResourceHandler.java:325)在 org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:550)在 org.jboss.web.tomcat.service.WebCtxLoader.start(WebCtxLoader.java:158)

它期望每个@Resource 的映射名称就像一些 ejb.

It expects mapped-name for each @Resource like some ejb.

我见过类似的问题,但没有任何答案,例如:

I've seen similar questions but they are without any answer e.g.:

@Resource 注解在 JBoss5.0.1 上无法正常工作

请指教.

阿迪

推荐答案

实际上你的问题是 JBoss 并没有忽略 @Resource 注释 - 它试图根据 EJB 规则处理它们而不是离开他们去春天.

Actually your problem is that JBoss doesn't ignore @Resource annotations - it tries to handle them according to EJB rules instead of leaving them to Spring.

也许可以在 JBoss 配置中的某处禁用此功能,但最简单的解决方案是将 @Resource 替换为 @Autowired@Inject>.

Perhaps this feature can be disabled somewhere in JBoss configuration, but the simpliest solution would be to replace @Resource with @Autowired or @Inject.

这篇关于JBoss 5.1:Spring @Resource 注释不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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