在Eclipse中运行一个非常简单的Weld SE项目

And*_*rey 4 java eclipse jboss-weld

我一直在我的网络应用程序中使用Seam 2(也开始研究Java EE 6),几天前我发现Seam的CDI可以在Weld的SE应用程序中使用.根据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!");
    }
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个新的Java Application Run Configuration并指示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
Run Code Online (Sandbox Code Playgroud)

那我错过了什么?

Tho*_*sen 7

你需要把它变成一个bean存档.在类路径中添加一个空的META-INF/beans.xml.