Reputation: 37
I'm currently testing CDI 2.0 for Java SE (weld) - I read, that it won't be necessary to use a beans.xml, so I tried this out:
Hallo.class:
public class Hallo {
public String sayHallo() {
return "hallo";
}
}
Then i have a Test.class:
@ApplicationScoped
public class Test {
@Inject Hallo hallo;
public String sayHallo() {
return hallo.sayHallo() + " from Test";
}
}
And finally here im trying to use CDI:
public class Demo {
public static void main(String[] args) {
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
/** disable discovery and register classes manually */
try (SeContainer container = initializer.disableDiscovery().addPackages(Demo.class).initialize()) {
Test test = container.select(Test.class).get();
test.sayHallo();
}
}
}
Unfortunately, it does not work. I get this Messages:
Okt 10, 2018 2:22:04 PM org.jboss.weld.bootstrap.WeldStartup INFO: WELD-000900: 3.0.5 (Final)
Okt 10, 2018 2:22:05 PM org.jboss.weld.bootstrap.WeldStartup startContainer INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent INFO: WELD-ENV-002003: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 initialized
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer shutdown INFO: WELD-ENV-002001: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 shut down
What am I missing?
Thanks in advance.
Upvotes: 0
Views: 1395
Reputation: 21144
The CDI container is working fine.
Transactional services not available
states you are not running under a Transaction Manager, which you'd have (almost) by default running inside an application server.
Upvotes: 2