Search code examples
javaglassfishjava-ee-6cdi

CDI @inject null pointer


i'm trying to use CDI but the injection doesn't work, the object instance is not created and i'm getting a null pointer on this: greetObj.greet("Champion");

I'm trying to Inject a bean in an EJB: my EJB:

    public @Stateless class CDIEjbBean implements CDIEjb {

    @Inject Greeting greetObj;
    public String getGreeting() {
        return greetObj.greet("Champion");
    }
}

and the greeting objects &qualifiers

@Default
public class Greeting {

    public String greet(String name) {
        return "Hello, " + name + ".";
    }
}

@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface Informal {}

@Informal
public class InformalGreeting extends Greeting{
    public String greet(String name) {
        return "Hi, " + name + ".";
    }
}

Any Idea? I'm on JDK6_21 glassfish 3.1

Thank you

Alexis


Solution

  • I've missed the first line on the JEE6 tutorial: > Configuring a CDI Application An application that uses CDI must have a file named beans.xml.