Netbeans:奇怪的焊接行为
按照官方文档我实现了非常简单的 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 到底是如何运行我的应用程序的?这种奇怪的行为有意义还是应该被视为错误?
Following the official documentation I implemented a very simple Java SE Weld quickstart class.
@Singleton
public class TesteCDI {
public void printHello(@Observes ContainerInitialized event,
@Parameters List<String> parameters) {
System.out.println("Hello Weld!" + parameters);
}
}
My run configuration fires org.jboss.weld.environment.se.StartMain
Here is the funny part.
If I don't create the Jar file (clicking in "Clean and Build"), my message isn't printed.
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
If I do create the Jar file, everything runs fine, both from the command line and from Netbeans. So I assumed Netbeans was running the application from the jar.
The problem is... It isn't.
If I update my Test class and run from Netbeans, it picks the changes. If I run the jar from command line it just prints the old message.
If I clean my project, Netbeans launch configuration stops printing the messsage.
Can anyone explain how exactly is Netbeans running my Application? Does this odd behavior make sense or should it be considered a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果您忘记 META-INF/beans.xml,焊接不会拾取您带注释的组件,您是否检查类路径中是否有 META-INF/beans.xml?
I think weld doesn't pick up your annotated components if you forget the META-INF/beans.xml, did you check if there is a META-INF/beans.xml in the classpath?