焊接没有正确初始化 [英] Weld not initializing properly

查看:117
本文介绍了焊接没有正确初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为JavaEE7中的学习CDI设置基本环境。我有以下代码用于启动 Weld 。只是启动和关闭。

I am setting up basic environment for learning CDI in JavaEE7. I have the following code for starting Weld. Just a startup and shutdown.

package com.anshbansal;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;

public class Main {
    public static void main(String[] args) {
        Weld weld = new Weld();
        WeldContainer container = weld.initialize();
        weld.shutdown();
    }
}

我正在控制台上关注。

I am getting following on my console.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/Softs/Programming/Java/Java%20JARs/JBoss%20Weld-2.0.3/jar/weld-se.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/Softs/Programming/Java/Java%20JARs/JBoss%20Weld-2.0.3/jar/weld-servlet.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO org.jboss.weld.Version - WELD-000900 2.0.3 (Final)
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

有问题的行是 WELD-000101交易服务不可用。注入@Inject UserTransaction不可用。将同步调用事务观察器。。这只是意味着依赖注入不起作用。但我不确定是什么问题。我在 CLASSPATH 中添加了 weld-se.jar 。我甚至没有达到初始化对象的意义,为什么会出现这个问题呢?

The problematic line is WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.. This simply means that Dependency injection will not work. But I am not sure what is the problem. I have added weld-se.jar in my CLASSPATH. I have not even reached the point of initializing an object then why is this problem occurring?

Weld的官方文档也提供了我在阅读此答案后获得的相同代码。 Antonio Goncalves一书中的Beginning Java EE 7中使用了相同的代码。我已经从这个github位置。因此,如果我使用了正确的类路径并且没有创建任何对象,那么为什么会出现这个问题呢?

Weld's official documentation also gives same code which I got after reading this answer. The same code is used in the book "Beginning Java EE 7" by "Antonio Goncalves". I have verified the imports from this github location. So if I have used correct class path and have not created any object then why is this problem occurring?

推荐答案

运行Java EE应用程序需要应用程序服务器(或容器)。这个容器让你的生活变得简单,关于运行企业应用程序所需的不同服务(安全性,消息传递,事务等等)的集成。

Running Java EE application requires an Application server (or container). This container makes your life far simple regarding the integration of different services (security, messaging, transaction, etc...) needed to run an enterprise application.

如果你不喜欢使用应用程序服务器(就像你在你的例子中所做的那样)你必须自己进行这种集成(即构建自己的服务器)。由于服务器存在,这是一项非常困难和无用的任务。

If you don't use an application server (like you are doing in your example) you have to make this integration yourself (i.e build your own server). That's a very hard and useless task since servers exist.

您在问题中显示的代码是如何使用Weld的专有部分手动启动CDI容器当你不想要或可以使用容器时。

The code you show in your question is how you can use the proprietary part of Weld to start a CDI container by hand when you don't want or can use a container.

如果你仔细阅读安东尼奥的书,你会在页面xxxiv 上看到部分'下载并运行代码'声明您需要在Glassfish 4上部署代码,Glassfish 4是开源Java EE 7服务器之一(另一个是 JBoss Wildfly

If you read carefully Antonio's book, you'll see that on page xxxiv in section 'Download and Running the Code' it is stated that you need to deploy your code on Glassfish 4, one of the open source Java EE 7 server (the other being JBoss Wildfly)

附录A 页面539 )以非常精确的方式描述如何设置环境以运行书籍示例和简单的Java EE应用程序。请按照本部分的说明进行操作,您将看到开发和部署Java EE 7应用程序非常简单。

Appendix A of the book (page 539) describe in a very precise way how to set up your environment to run book examples and simple Java EE applications. Please follow instruction in this part and you'll see that developing and deploying Java EE 7 application si very simple.

这篇关于焊接没有正确初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆