Simple J2EE project to test CDI capabilities on a non JEE environment
- The following example initializes the Application class in the CDI context.
public static void main(String[] args) {
CdiContext context = CdiContext.INSTANCE;
Application application = context.getBean(Application.class);
application.run();
}
- After the initialization, the Application class can use the CDI injectors to create instances of other objects and use other CDI capabilities, like qualification and other stuff
@Singleton
public class Application {
@Inject @Type(GreetingType.FORMAL)
Greeting greeting;
public void run() {
System.out.println(greeting.greet());
}
}