Announcement Announcement Module
No announcement yet.
Dependency injection via @Resource when deploying on JBoss Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dependency injection via @Resource when deploying on JBoss

    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:

    public class MyNonStandardClass implements MyNonStandardInterface {
      @Resource  // <--- outside the container this is correctly processed by Spring
      AnotherNonStandardInterface registry;
      public void 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:

    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(
      at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXml(
      at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(
      at org.jboss.web.tomcat.service.WebCtxLoader.start(
      at org.apache.catalina.core.StandardContext.start(
      at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(
      at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(
      at org.jboss.web.deployers.AbstractWarDeployment.start(
      at org.jboss.web.deployers.WebModule.startModule(
      at org.jboss.web.deployers.WebModule.start(
      ... (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,

  • #2

    any news on this issue? I'm currently running into the same problem...

    Kind regards



    • #3
      I have also tried replacing @Resource with

      this didn't work either. expected at least 1 matching bean Unsatisfied dependency of type


      • #4
        I have replaced the annotations with @Autowired in order to let them be processed by Spring and ignored by the container (@minaelks: it should work, if the spring context is correctly initialized). If no one has any alternative here, there might not be any yet.

        Weld 1.0 (JSR 299) has been released a short time ago. I think it will greatly improve dependency injection in a JEE environment. I haven't seen a Spring-related SPI implementation, but Seam has a very good way to integrate Spring, so I believe it will be in place soon, if it is not already.


        • #5
          Jsr 330

          I forgot to mention JSR 330 in my last message on this thread, but JSR 299 relies on it.

          @Inject and @Named from JSR 330 work without problems in Spring 3 and are also referenced in the documentation (here and here). I have been using them without problems since switching to Spring 3 in some projects.