11 Replies Latest reply: Sep 21, 2011 6:00 PM by John Ament RSS

Seam JMS - Inject into application scoped bean?

Joshua Davis Expert

I'm trying out Seam JMS resource injection in my new CDI/Weld application and I'm having a little trouble injecting TopicProducer and Session (so I can create messages) into an @ApplicationScoped bean like this:


@ApplicationScoped
public class MyBean
{
    @Inject
    private Logger log;

    @Inject
    @JmsDestination(jndiName="topic/myTopic")
    private TopicPublisher topicPublisher;

    @Inject
    @JmsSession(transacted=false, acknowledgementType=Session.CLIENT_ACKNOWLEDGE)
    private Session session;

... yadda yadda ...
}




Weld says the following:



14:33:09,860 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.unit."my-webapp.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."my-webapp.war".WeldService: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [ConnectionFactory] with qualifiers [@Any @Module] declared as [[field] @Resource @Module @Produces @ApplicationScoped private org.jboss.seam.jms.impl.inject.ConnectionProducer.cf]] must be @Dependent scoped
        at org.jboss.as.weld.services.WeldService.start(WeldService.java:96)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27]
        at java.lang.Thread.run(Thread.java:662) [:1.6.0_27]
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [ConnectionFactory] with qualifiers [@Any @Module] declared as [[field] @Resource @Module @Produces @ApplicationScoped private org.jboss.seam.jms.impl.inject.ConnectionProducer.cf]] must be @Dependent scoped
        at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.checkEEResource(EEResourceProducerField.java:133)
        at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.initialize(EEResourceProducerField.java:125)
        at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:119)
        at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:227)
        at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:378)
        at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
        at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
        ... 5 more




Any ideas?   I'm not really sure what Weld is complaining about.

  • 1. Re: Seam JMS - Inject into application scoped bean?
    John Ament Master

    What version of Seam JMS are you using?  Try 3.1.0.Beta2, it seems like you're using a much older version.  What version of AS are you on?

  • 2. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    I am using JBoss 7.0.1.Final.   I'll check the Seam JMS version in the morning when I get to work.  I think it was 3.0.0.Final.


    The app is packaged as a WAR, if that matters.

  • 3. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    Seam JMS 3.0.0.Alpha1 from seam-bom 3.0.0.Final.


    Should I upgrade {{seam-bom}} as well?

  • 4. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    I tried upgrading seam-bom to 3.1.0.Beta2, but now most of my code fails to compile because org.jboss.logging isn't a transitive dependency any more.   Looks like I need to see what changed in Solder.

  • 5. Re: Seam JMS - Inject into application scoped bean?
    Jason Porter Master

    Yes, please update the BOM as well. There are other changes in modules that fix issues others have expected.

  • 6. Re: Seam JMS - Inject into application scoped bean?
    Jason Porter Master

    Joshua Davis wrote on Sep 21, 2011 11:53:


    I tried upgrading seam-bom to 3.1.0.Beta2, but now most of my code fails to compile because org.jboss.logging isn't a transitive dependency any more.   Looks like I need to see what changed in Solder.


    It's in the solder-logging dep.

  • 7. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    Adding seam-solder-logging to the dependencies in the WAR module fixed the compile problem, but now I get this exception when the app is deploying in JBoss AS 7.0.1.Final:


    12:25:09,305 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.deployment.unit."my-webapp.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."my-webapp.war".POST_MODULE: Failed to process phase POST_MODULE of deployment "pricefeed-webapp.war"
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
            at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27]
            at java.lang.Thread.run(Thread.java:662) [:1.6.0_27]
    Caused by: java.lang.NoClassDefFoundError: org/jboss/logmanager/Logger$AttachmentKey
            at org.jboss.seam.solder.logging.internal.JBossLogManagerProvider.<clinit>(JBossLogManagerProvider.java:36)
            at org.jboss.seam.solder.logging.internal.LoggerProviders.findProvider(LoggerProviders.java:33)
            at org.jboss.seam.solder.logging.internal.LoggerProviders.<clinit>(LoggerProviders.java:28)
            at org.jboss.seam.solder.logging.internal.Logger.getLogger(Logger.java:2164)
            at org.jboss.seam.logging.Logger.<init>(Logger.java:44)
            at org.jboss.seam.logging.Logger.getLogger(Logger.java:1965)
            at org.jboss.seam.logging.Logger.getLogger(Logger.java:1991)
            at org.jboss.seam.international.status.TypedStatusMessageBundleExtension.<clinit>(TypedStatusMessageBundleExtension.java:59)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_27]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [:1.6.0_27]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [:1.6.0_27]
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [:1.6.0_27]
            at org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.loadExtension(WeldPortableExtensionProcessor.java:117)
            at org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.loadAttachments(WeldPortableExtensionProcessor.java:100)
            at org.jboss.as.weld.deployment.processors.WeldPortableExtensionProcessor.deploy(WeldPortableExtensionProcessor.java:86)
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)
            ... 5 more
    



    With seam-solder:3.0.0.Final it was starting up normally without a dependency on jboss-logging-manager or whatever.


  • 8. Re: Seam JMS - Inject into application scoped bean?
    Jason Porter Master

    Yeah, we'll get that fixed in Beta3. Logging changed in Beta2 and it broke a bunch of stuff, sorry about that. Add this stanza to a file called jboss-deployment-structure.xml in WEB-INF.



    <jboss-deployment-structure>
      <deployment>
        <dependencies>
          <module name="org.jboss.logmanager" />
        </dependencies>
      </deployment>
    </jboss-deployment-structure>



    More information can be found in the AS7 docs

  • 9. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    Thanks! It compiles and starts now.   However, it looks like my logging configuration in standalone.xml is being ignored.   I have my category 'com.foo' set to DEBUG, but I see no debug messages in log/server.log at all.

  • 10. Re: Seam JMS - Inject into application scoped bean?
    Joshua Davis Expert

    Added Seam JMS, and the app deploys and starts up.   That's good.


    However, when I try the initial example:


    @ApplicationScoped
    public class MyBean
    {
        @Inject
        private Logger log;
    
        @Inject
        @JmsDestination(jndiName="topic/myTopic")
        private TopicPublisher topicPublisher;
    
        @Inject
        @JmsSession(transacted=false, acknowledgementType=Session.CLIENT_ACKNOWLEDGE)
        private Session session;
    
    ... yadda yadda ...
    }
    



    Now I get this exception:


    15:39:37,257 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.deployment.unit."my-webapp.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."my-webapp.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [TopicPublisher] with qualifiers [@JmsDestination] at injection point [[field] @Inject @JmsDestination private com.pep.pfm.PublisherImpl.topicPublisher]
            at org.jboss.as.weld.services.WeldService.start(WeldService.java:96)
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
            at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27]
            at java.lang.Thread.run(Thread.java:662) [:1.6.0_27]
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [TopicPublisher] with qualifiers [@JmsDestination] at injection point [[field] @Inject @JmsDestination private com.pep.pfm.PublisherImpl.topicPublisher]
            at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:270)
            at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:106)
            at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:129)
            at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:351)
            at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:336)
            at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:404)
            at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)
            at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
    
    


  • 11. Re: Seam JMS - Inject into application scoped bean?
    John Ament Master

    It's probably a documentation issue.  The current version of MessagePubSubProducer:


    https://github.com/seam/jms/blob/develop/impl/src/main/java/org/jboss/seam/jms/impl/inject/MessagePubSubProducer.java


    Only provides injection for MessageProducer/MessageConsumer, not Topic or Queue APIs.  This was done for a couple of reasons:


    1. The JMS 2.0 EG is in the process of deprecated the P2P/PubSub specific interfaces as a part of JMS 2.0.  I wanted to align this.
    2. Since MessageProducer is extended by TopicPublisher and QueueSender, we can't provide an API that can inject both using the same qualifier.


    I think if you switch, it'll work.  Note that your specific example won't work with AS either, you've ended up with two sessions, HornetQ requires that the messages be created and sent by the same session.