4 Replies Latest reply on Jan 7, 2010 7:26 PM by gavin.king

    Observes annotation in ejb 3.1 on fg3

    psychollek

      I tried to use the @Observes annotation in my application, and got this exception while deploying:


      Caused by: org.jboss.weld.DefinitionException: Observer method must be static or business method: method public void pl.labat.nieruchomosci.poldata.acounting.services.AcountingEventListenerBean.listenOfferAdded(pl.labat.nieruchomosci.poldata.services.events.OfferAddedEvent) on class Class [@Stateless]AcountingEventListenerBean
      Constructor []public AcountingEventListenerBean();
        Method void []public listenToCreditUpdate([@Observes][]CreditUpdateEvent);
        Method void []public listenOfferAdded([@Observes][]OfferAddedEvent);
        Method void []public final wait();
        Method void []public final wait([][]long, [][]int);
        Method void []public final native wait([][]long);
        Method int []public native hashCode();
        Method Class []public final native getClass();
        Method boolean []public equals([][]Object);
        Method String []public toString();
        Method void []public final native notify();
        Method void []public final native notifyAll();
              at org.jboss.weld.bean.SessionBean.checkObserverMethods(SessionBean.java:375)
              at org.jboss.weld.bean.SessionBean.initialize(SessionBean.java:124)
              at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:111)
              at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
              at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)
              at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:167)



      In the AcountingEventListenerBean (@Stateless annotation) both of the methods in question (that is with @Observes) are exposed through remote business interface (decorated with javax.ejb.Remote annotation).


      application server in use : Glassfish V3



        • 1. Re: Observes annotation in ejb 3.1 on fg3
          psychollek


          @Stateless
          public class AcountingEventListenerBean implements AcountingEventListenerRemote{
          
              @Override
              public void listenToCreditUpdate(@Observes CreditUpdateEvent event){
          
              }
          
              @Override
              public void listenOfferAdded(@Observes OfferAddedEvent evt){
          
              }
          }





          @Remote
          public interface AcountingEventListenerRemote {
          
              public void listenToCreditUpdate(CreditUpdateEvent event);
          
              public void listenOfferAdded(OfferAddedEvent evt);
          
          }





          public class CreditUpdateEvent implements Serializable{
          
              private static final long serialVersionUID = 768718676411L;
          
              private final long user;
              private final int amount;
          
              public CreditUpdateEvent(int amount, long user){
                  this.amount = amount;
                  this.user = user;
              }    
          
              public int getAmount() {
                  return amount;
              }
          
              public long getUser(){
                  return user;
              }
          
          
          }





          
          public class OfferAddedEvent implements Serializable {
          
              private static final long serialVersionUID = 168743443272735L;
          
              private final long userId;
              private final long offerId;
          
              public OfferAddedEvent(long userId,long offerId){
                  this.userId = userId;
                  this.offerId = offerId;
              }
          
              public long getUserId() {
                  return userId;
              }
          
              public long getOfferId() {
                  return offerId;
              }
          
          }
          
          






          • 2. Re: Observes annotation in ejb 3.1 on fg3
            nickarls

            https://jira.jboss.org/jira/browse/WELD-364


            It is possible a leftover-restriction from a previous spec version.

            • 3. Re: Observes annotation in ejb 3.1 on fg3
              psychollek

              bah, so I only need to change interface to local ? I thought only remote would work, as when I used nonexposed methods (which are local - accessible through no interface view)

              • 4. Re: Observes annotation in ejb 3.1 on fg3
                gavin.king

                The spec says that producer/observer/disposer methods must be business methods of the EJB. Therefore, a method of a remote interface is acceptable. Apparently this is a bug in Weld. However, note that remote interfaces are not bean types of the EJB, so you can't inject an EJB that has only remote interfaces, unless you define it as a resource.