Announcement Announcement Module
Collapse
No announcement yet.
Dependency injection via @Resource when deploying on JBoss Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    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

  • #2
    Hi,

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

    Kind regards

    Christian

    Comment


    • #3
      I have also tried replacing @Resource with
      @Autowired
      @Qualifier("name")

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

      Comment


      • #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.

        Comment


        • #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.

          Comment

          Working...
          X