我一直在我的 Web 应用程序中使用 Seam 2(也开始研究 Java EE 6),几天前我发现可以在带有 Weld 的 SE 应用程序中利用 Seam 的 CDI。根据 Weld 的Weld SE文档页面,设置很简单。因此,我尝试使用单个类 HelloWeld、weld-se.jar 和 log4j jar 设置 Eclipse 项目。
@Singleton
public class HelloWeld
{
public void printHello(@Observes ContainerInitialized event, @Parameters List<String> parameters)
{
System.out.println("Hello Weld!");
}
}
我创建了一个新的 Java 应用程序运行配置并指示org.jboss.weld.environment.se.StartMain
为主类。当我运行这个项目时,我毫不意外地发现,HelloWeld 从未被调用过。我得到的只是一些日志条目,作为 Weld 正确启动的指示:
11:54:39,397 INFO [weld.Version] WELD-000900 1.0.1 (Final)
11:54:39,428 INFO [weld.Bootstrap] WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
11:54:39,944 WARN [model.InterceptionTypeRegistry] Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
11:54:39,944 WARN [model.InterceptionTypeRegistry] Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
那么我错过了什么?