What is the recommended way to use annotation-based dependency injection via @Resource when deploying to a container that processes these annotations independently of the spring configuration? I am running into a problem on JBoss 5.1.
I have a problem in my WAR. It contains the following class:
Code:
public class MyNonStandardClass implements MyNonStandardInterface {
@Resource // <--- outside the container this is correctly processed by Spring
AnotherNonStandardInterface registry;
public void doSomething(…) {
registry.doSomething();
}
…
}
As indicated in the comment above, I do not have any problems deploying this application to Tomcat or Jetty, but as soon as I deploy it to JBoss, some automatic processing (I assume only validation) takes place at deploy time. This results in the following error:
Code:
ERROR [StandardContext] Context [/myservice] startup failed due to previous errors
java.lang.RuntimeException: mapped-name is required for MyNonStandardClass/registry of deployment myservice.war
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXmlResourceEnvRefs(WebResourceHandler.java:287)
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXml(WebResourceHandler.java:325)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:550)
at org.jboss.web.tomcat.service.WebCtxLoader.start(WebCtxLoader.java:158)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4272)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
... (47 more)
I think, I can understand the error, but besides from changing the annotation from @Resource to @Autowired, is there a recommended practices on what can be done?
Can I somehow either
- Tell JBoss not to process certain @Resource annotations?
- Configure Spring as a provider to process these annotations?
Thank you,
Kariem