3
votes

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

1
Do you have an empty beans.xml in your module?Perception
well well, 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. The file can be completely empty (it has content > only in certain limited situations), but it must be present. For a web > application, the beans.xml file must be in the WEB-INF directory. For > EJB modules or JAR files, the beans.xml file must be in the META-INF > directory. Even when using qualifiers. Thank you anywaybodtx
No problem, glad the issues fixed.Perception

1 Answers

3
votes

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.