Search code examples
javajakarta-eeannotationsejbobserver-pattern

Get Observer pattern on EJBs working on my web app


I am trying to get the EJB Observer pattern to work and it seems very straight forward from examples like this:

http://www.devchronicles.com/2011/11/javaee-revisits-design-patterns_28.html

however when I implement the method:

public void doLogging(@Observes String message){
    System.out.println("Observed:"+message);
}

the @Observer annotation import does not get inserted.

Also if I do it manually as:

import javax.enterprise.event.Observes;

it does not work looking like I do not have the classes/jars.

I am using EJB 3.0 and am hoping this is not present only in 3.1. If this is the case how can i get the Observer pattern in EJB 3.0?


Solution

  • It's not part of EJB, but of CDI (JSR-299).

    CDI is new since Java EE 6, which also covers EJB 3.1. As you've only EJB 3.0 at hands, this means that you're still on Java EE 5. These days we're already at Java EE 7. It's about time to upgrade.

    Examples of Java EE 7 servers are JBoss WildFly 8.x, Oracle GlassFish 4.x, Apache TomEE 2.x and IBM WebSphere 9.x. Examples of Java EE 6 servers are JBoss AS 6.x/7.x, Oracle GlassFish 3.x, Apache TomEE 1.x and IBM WebSphere 8.x.

    See also: