0

按照官方文档,我实现了一个非常简单的 Java SE Weld 快速入门类。

@Singleton
public class TesteCDI {

    public void printHello(@Observes ContainerInitialized event, 
         @Parameters List<String> parameters) {
       System.out.println("Hello Weld!" + parameters);
   }
} 

我的运行配置触发org.jboss.weld.environment.se.StartMain

这是有趣的部分。如果我不创建 Jar 文件(单击“清理并构建”),则不会打印我的消息。

54 [main] INFO org.jboss.weld.Version - WELD-000900 1.1.0 (Final)
110 [main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
388 [main] WARN org.jboss.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
388 [main] WARN org.jboss.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled

如果我确实创建了 Jar 文件,那么无论从命令行还是从 Netbeans,一切都运行良好。所以我假设 Netbeans 正在从 jar 中运行应用程序。

问题是……不是

如果我更新我的测试类并从 Netbeans 运行,它会选择更改。如果我从命令行运行 jar,它只会打印旧消息。

如果我清理我的项目,Netbeans 启动配置会停止打印消息。

谁能解释一下 Netbeans 究竟是如何运行我的应用程序的?这种奇怪的行为有意义还是应该被视为错误?

4

1 回答 1

1

我认为如果您忘记 META-INF/beans.xml,weld 不会拾取您的注释组件,您是否检查了类路径中是否有 META-INF/beans.xml?

于 2011-08-12T17:11:15.740 回答