CDI SE - bootstraping in a standalone app
ozizka May 24, 2011 7:40 AMHi,
I'm trying to get CDI working in a standalone app.
Following http://docs.jboss.org/weld/reference/latest/en-US/html_single/#weld-se ,
I added weld-se artifact, and my app now looks like this:
@Singleton
public class MyApp {
public static void main(String[] args) throws AppException { ... }
}// class
public class MyAppWeld {
public static void main(String[] args) throws AppException {
WeldContainer weld = new Weld().initialize();
MyApp app = weld.instance().select(MyApp.class).get();
myApp.main(args);
}
}// class
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:weld="http://jboss.org/schema/weld/beans" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"> <weld:scan> <weld:include name="**"/> </weld:scan> </beans>
This way, I'd expect Weld to bootstrap and start working on the app object and further on the graph of deps.
But that doesn't happen, and I get:
33 [main] INFO org.jboss.weld.Version - WELD-000900 1.1.1 (Final) 54 [main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 273 [main] WARN org.jboss.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 273 [main] WARN org.jboss.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled Exception in thread "main" org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [class org.jboss.myapp.MyApp]; Bindings: [@javax.enterprise.inject.Default()] at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:809) at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:108) at org.jboss.jawabot.JawaBotAppWeld.main(JawaBotAppWeld.java:17)
What am I doing wrong?
Thanks,
Ondra