[英]How to add Weld CDI support to a working Jetty application?
我目前正在使用Jetty 9部署WAR文件。
对于依赖关系管理,我使用的是Gradle; 我的build.gradle
文件如下所示:
apply plugin: 'java'
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
/**
* Jersey.
*/
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.1'
compile 'org.glassfish.jersey.core:jersey-server:2.22.1'
/**
* Weld CDI.
*/
compile 'org.jboss.weld.servlet:weld-servlet-core:2.3.2.Final'
/**
* JUnit.
*/
testCompile 'junit:junit:4.12'
}
我的web.xml
如下所示:
<web-app version="3.0">
<display-name>Example Api</display-name>
<servlet>
<servlet-name>RESTful Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RESTful Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
</web-app>
但是,当我尝试部署时,会得到以下堆栈跟踪:
[2015-12-16 09:13:33,315] Artifact Gradle : api : api.war: Artifact is being deployed, please wait...
Dec 16, 2015 9:13:36 PM org.jboss.weld.environment.servlet.EnhancedListener onStartup
INFO: WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
Dec 16, 2015 9:13:36 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.3.2 (Final)
Dec 16, 2015 9:13:36 PM org.jboss.weld.environment.servlet.WeldServletLifecycle initialize
INFO: WELD-ENV-000028: Weld initialization skipped - no bean archive found
Dec 16, 2015 9:13:36 PM org.jboss.weld.environment.servlet.Listener contextInitialized
INFO: WELD-ENV-001007: Initialize Weld using ServletContextListener
Dec 16, 2015 9:13:36 PM org.jboss.weld.environment.servlet.WeldServletLifecycle initialize
INFO: WELD-ENV-000028: Weld initialization skipped - no bean archive found
后跟java.lang.IllegalStateException: Singleton not set for STATIC_INSTANCE => []
。
有人可以告诉我要完成此工作需要做什么吗?
我只是想在Jetty中@Inject
我的依赖项,但是我发现自己连续几天都在努力进行配置设置...
如果要在码头配送上使用Weld / CDI,则需要执行以下操作。
这在“ 环境:码头”的Weld / CDI方面有部分记录
WEB-INF/lib
目录中包括适合您使用的焊罐。 (让我们称之为mywebapp.war
) ${jetty.base}
目录,并进行正确配置。 ${jetty.home}
或$JETTY_HOME
任何内容。 如果执行此操作,则说明您已经没有正确使用码头。 ${jetty.base}/webapps/mywebapp.xml
的文件查看标准Servlet类加载器隔离。 mywebapp.war
复制到${jetty.base}/webapps/
目录。 ${jetty.base}
设置示例
$ mkdir /path/to/mybase
$ cd /path/to/mybase
$ java -jar /path/to/jetty-dist/start.jar --add-to-start=http,deploy
${jetty.base}/webapps/mywebapp.xml
示例
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/weld-numberguess</Set>
<Set name="war"><Property name="jetty.webapps" default="."/>/mywebapp.war</Set>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.servlet.FilterHolder</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.servlet.ServletHolder</Arg>
</Call>
</Configure>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.