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

发布于 2024-09-13 17:16:36 字数 1239 浏览 0 评论 0原文

我一直在我的 Web 应用程序中使用 Seam 2(也开始研究 Java EE 6),几天前我发现 Seam 的 CDI 可以在带有 Weld 的 SE 应用程序中使用。根据 Weld 的文档页面 Weld SE< /a> 设置很简单。因此,我尝试使用单个类 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

那么我错过了什么?

I've been using Seam 2 (also started looking into Java EE 6) in my web apps and a couple of days ago I found out that Seam's CDI can be leveraged in an SE application with Weld. According to Weld's Documentation page for Weld SE the setup is trivial. So I tried to setup an Eclipse project with a single class HelloWeld, weld-se.jar and the log4j jars.

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

I created a new Java Application Run Configuration and indicated org.jboss.weld.environment.se.StartMain as the main class. When I ran the project I found out, without any surprise what-so-ever, that HelloWeld was never called. All I got was a few log entries as an indication that Weld booted correctly:

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

So what am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2024-09-20 17:16:36

您需要将其设为 Bean 存档。将空 META-INF/beans.xml 添加到类路径中。

You need to make it a bean archive. Add an empty META-INF/beans.xml to your classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文