CDI 注入在 Servlet 中不起作用

2024-01-14

我真的需要你的帮助。我现在正在研究这个问题几周或几个月。对于这么长的帖子,我深表歉意,但我想尽可能准确地解释问题和我的设置。

我的 JAVA EE 6 Web 应用程序主要包含 3 个 Servlet:javax.faces.webapp.FacesServlet,一个 StreamingServlet 扩展javax.servlet.http.HttpServlet和一个 ClientServlet 扩展org.eclipse.jetty.websocket.WebSocketServlet。我想将 CDI 与这些 Servlet 一起使用,但它仅适用于 FacesServlet,更准确地说,适用于 JSF 操作路由到的 Bean。 CDI 注入不适用于其他 2 个 Servlet。

我的项目的设置如下:Maven 3.0.4,Jetty 8.1.4(jetty-maven-plugin),MyFaces 2.1.6,Weld 1.1.8。

文件pom.xml包含 CDI 的依赖项:

...
<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.1.EDR1.2</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>jsr250-api</artifactId>
    <version>1.0</version>
</dependency>
<dependency>
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet</artifactId>
    <version>${weld.version}</version>
    <scope>runtime</scope>
</dependency>
...

文件src/main/webapp/WEB-INF/beans.xml仅包含用于激活 CDI 的空 beans 元素:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

文件scr/main/webapp/WEB-INF/jetty-env.xml包含用于通过 JNDI 获取 bean 管理器的 Jetty 特定配置:

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>
            <Ref id="webAppCtx" />
        </Arg>
        <Arg>BeanManager</Arg>
        <Arg>
            <New class="javax.naming.Reference">
                <Arg>javax.enterprise.inject.spi.BeanManager</Arg>
                <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
                <Arg />
            </New>
        </Arg>
    </New>
</Configure>

文件src/main/webapp/WEB-INF/web.xml包含 servlet 侦听器和用于引导 CDI 的 BeanManager 参考:

...
<listener>
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

<resource-env-ref>
    <description>Object factory for the CDI Bean Manager</description>
    <resource-env-ref-name>BeanManager</resource-env-ref-name>
    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
...

通过这些设置,我在使用运行应用程序时总是遇到以下错误mvn 码头:运行(第一行最重要):

2012-07-31 11:09:33,546 [main] ERROR org.jboss.weld.environment.jetty.JettyPost72Container - Unable to create JettyWeldInjector. CDI injection will not be available in Servlets, Filters or Listeners
java.lang.IllegalArgumentException: Cannot load class for org.jboss.weld.environment.jetty.WeldDecorator
    at org.jboss.weld.environment.servlet.util.Reflections.classForName(Reflections.java:58)
    at org.jboss.weld.environment.jetty.JettyPost72Container.initialize(JettyPost72Container.java:66)
    at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:162)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:764)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:406)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:756)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:242)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:699)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:256)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
    at org.eclipse.jetty.server.Server.doStart(Server.java:262)
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
    at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:516)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletContextHandler$Decorator
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:377)
    at org.jboss.weld.environment.servlet.util.Reflections.classForName(Reflections.java:51)
    ... 44 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.servlet.ServletContextHandler$Decorator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:377)
    ... 56 more

应用程序正在运行,但异常消息指出:CDI 注入在 Servlet 中不可用。

前几天,我发现了一篇文章使用 Weld-Servlet 和 Jetty 插件从 Maven 启动 CDI Web 应用程序 http://agorava.org/news/2012/07/10/Starting-a-CDI-webapp-from-Maven-with-Weld-servlet-and-jetty-plugin/尤其是该部分允许在 servlet 中注入的最后一个技巧。作者解释说,Weld 需要装饰一些 Jetty 内部类,以便在 servlet 中使用 @Inject 注解,并且我们必须告诉 Jetty 类加载器在哪里可以找到这个类,以便让 Weld servlet 来装饰它。

我等待这个特殊信息已经很久了。所以我添加了文件src/main/webapp/WEB-INF/jetty-context.xml:

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="serverClasses">
        <Array type="java.lang.String">
            <Item>org.eclipse.jetty.servlet.ServletContextHandler.Decorator</Item>
        </Array>
    </Set>
</Configure> 

我还更新了pom.xml为了合并文件 jetty-context.xml (最后一行):

...
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
        <webApp>
            <contextPath>/${project.build.finalName}</contextPath>
        </webApp>
        <jettyEnvXml>src/main/webapp/WEB-INF/jetty-env.xml</jettyEnvXml>
        <contextXml>src/main/webapp/WEB-INF/jetty-context.xml</contextXml>
        ...

现在上面的错误消失了。那短暂的时刻我很高兴:)

在 src/main/resources/log4j.properties 中,我增加了 Weld 的日志级别:

...
log4j.logger.org.jboss.weld=DEBUG, stdout
log4j.additivity.org.jboss.weld=false
...

启动应用程序时,我收到以下焊接日志消息:

...
2012-07-31 12:00:08,968 [main] INFO  org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
2012-07-31 12:00:09,109 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000103 Enabled alternatives for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.Dependent, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ConversationScoped, interface javax.inject.Singleton]
Registered beans: 0
: [] []
2012-07-31 12:00:09,109 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000104 Enabled decorator types for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.Dependent, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ConversationScoped, interface javax.inject.Singleton]
Registered beans: 0
: []
2012-07-31 12:00:09,109 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000105 Enabled interceptor types for Manager
Enabled alternatives: [] []
Registered contexts: [interface javax.enterprise.context.SessionScoped, interface javax.enterprise.context.ApplicationScoped, interface javax.enterprise.context.Dependent, interface javax.enterprise.context.RequestScoped, interface javax.enterprise.context.ConversationScoped, interface javax.inject.Singleton]
Registered beans: 0
: []
2012-07-31 12:00:09,171 [main] INFO  org.jboss.weld.environment.jetty.JettyPost72Container - Jetty7 detected, JSR-299 injection will be available in Listeners, Servlets and Filters.
2012-07-31 12:00:09,265 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Implicit Bean [javax.enterprise.inject.spi.InjectionPoint] with qualifiers [@Default]
2012-07-31 12:00:09,265 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.DependentContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.util.MediaType] with qualifiers [@Any @Default]
2012-07-31 12:00:09,281 [main] WARN  org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
2012-07-31 12:00:09,281 [main] WARN  org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.web.LoginBean] with qualifiers [@Any @Default]
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.http.HttpRequestContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.http.HttpSessionContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.web.CustomerBean] with qualifiers [@Any @Default @Named]
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.bound.BoundConversationContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.ApplicationContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.util.LocaleBean] with qualifiers [@Any @Default @Named]
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.bound.BoundRequestContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.SingletonContext
2012-07-31 12:00:09,281 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [@Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.DataReader] with qualifiers [@Any @Default @Named]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.SessionBean] with qualifiers [@Any @Default @Named]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.ConnectionTable] with qualifiers [@Any @Default @Named]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.http.HttpConversationContext
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.servlet.ClientServlet] with qualifiers [@Any @Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.RequestContext
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-javax.enterprise.context.Conversation
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Implicit Bean [javax.enterprise.event.Event] with qualifiers [@Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.CustomerListBean] with qualifiers [@Any @Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.Customer] with qualifiers [@Any @Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.servlet.StreamingServlet] with qualifiers [@Any @Default]
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: org.jboss.weld.bean-flat-Built-in-org.jboss.weld.context.bound.BoundSessionContext
2012-07-31 12:00:09,296 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000106 Bean: Managed Bean [class de.telexiom.cardiom.SessionInfo] with qualifiers [@Any @Default]
2012-07-31 12:00:09,312 [main] DEBUG org.jboss.weld.Reflection - WELD-000601 interface javax.inject.Named is missing @Target. Weld will use this annotation, however this may make the application unportable.
2012-07-31 12:00:09,312 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000100 Weld initialized. Validating beans
...

我用Servlet 3.0 API,StreamingServlet 和 ClientServlet 是通过注释配置的。问题是应用程序范围的bean连接表 and 数据读取器未注入:

@WebServlet(value = "/stream", initParams = @WebInitParam(name = "maxIdleTime", value = "0"))
public class StreamingServlet extends HttpServlet
{
    @Inject
    private ConnectionTable connectionTable;
    ...

@WebServlet(value = "/push", loadOnStartup = 1, initParams = @WebInitParam(name = "maxIdleTime", value = "0"))
public class ClientServlet extends WebSocketServlet
{
    @Inject
    private ConnectionTable connectionTable;

    @Inject
    private DataReader dataReader;
    ...

调用(未)注入的属性,我总是得到 NullPointerExceptions。通过 web.xml 配置 Servlet 时,问题仍然存在。我对自己做错了什么不再有任何想法。阅读了所有关于 CDI 与 Jetty 和 Maven 结合的文章,我想知道是否我是唯一一个遇到这些注入问题的人。

在我的 JSF bean 类中UserBean.java注入有效,我不必使用setter方法来初始化属性connectionTable和dataReader。

在 DataReader 构造函数(以及 ConnectionTable 类)中使用下面的输出语句

@ApplicationScoped
public class DataReader implements Serializable
{
    ...
    public DataReader()
    {
        System.out.println("DataReader.DataReader(): " + this);
    }
    ...

我想知道标准输出上显示的 2 个 DataReader 实例:

...
2012-07-31 14:03:04,843 [qtp5435124-17] DEBUG org.jboss.weld.JSF - WELD-000504 Resuming conversation with id null
31.07.2012 14:03:05 org.apache.myfaces.util.ExternalSpecifications isUnifiedELAvailable
INFO: MyFaces Unified EL support enabled
DataReader.DataReader(): DataReader$Proxy$_$$_WeldClientProxy@506e6d
ConnectionTable.ConnectionTable(): ConnectionTable$Proxy$_$$_WeldClientProxy@93b16c

2012-07-31 14:03:19,093 [qtp5435124-16] DEBUG org.jboss.weld.JSF - WELD-000504 Resuming conversation with id null
DataReader.DataReader(): DataReader@1cbd382

前 5 行在基于表单的身份验证后打印,最后 2 行在第一次处理使用注入的 dataReader 属性的 JSF 操作时出现。由于 bean 是应用程序范围的,我真的很想知道 2 个构造函数传递。但从应用程序的行为来看,我认为它没有任何问题。

我的最后一个假设是 Servlet 以某种方式存在于分离的、独立的上下文或容器或类似的东西中。因为在另外 2 个 Servlet 中也不可能获取 FacesContext:FacesContext.getCurrentInstance() gives null。但我不知道这在某种程度上是否重要。

我希望任何人都可以帮助我解决这个问题。先感谢您

塞巴斯蒂安


错误很明显:

java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletContextHandler$Decorator

Weld 找不到上面的 Jetty 服务器类。之所以找不到这个类,是因为Jetty的类加载机制。 Jetty 的 WebAppClassloader 有一个不会加载的默认服务器类列表:请参阅http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading

Server Classes
-org.eclipse.jetty.continuation.             don't hide continuation classes
-org.eclipse.jetty.jndi.                     don't hide naming classes
-org.eclipse.jetty.plus.jaas.                don't hide jaas classes
-org.eclipse.jetty.websocket.                don't hide websocket extension
-org.eclipse.jetty.servlet.DefaultServlet    don't hide default servlet
org.eclipse.jetty.                           hide all other jetty classes

要允许 Jetty 加载此类,您需要添加“-org.eclipse.jetty.servlet”。到 jetty-web.xml 中的服务器类列表。

 <Configure class="org.eclipse.jetty.webapp.WebAppContext">
   <Call name="prependServerClass"><Arg>-org.eclipse.jetty.servlet.</Arg></Call>
 </Configure>

或者,如果您使用嵌入式码头,请调用以下方法:

 context.prependServerClass("-org.eclipse.jetty.servlet.");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CDI 注入在 Servlet 中不起作用 的相关文章

随机推荐

  • 如何在Javascript文件(.js)中使用Python Flask? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 当 Javascript 代码位于 HTML 文件中时 这不是问题 但是 当我将 script 标签的内容移至 js 文件以便在其他
  • 安装路径不可写R,无法更新包

    我正在尝试使用他们网站上的代码将 Bioconductor 安装到 R 中 当我输入代码 见下文 时 我收到一条错误消息 指出某些软件包无法更新 安装路径不可写 gt try http if https URLs are not suppo
  • 重命名 Kubernetes 中的部署

    If I do kubectl get deployments I get kubectl get deployments NAME DESIRED CURRENT UP TO DATE AVAILABLE AGE analytics re
  • 如何在 Django-rest-framework 序列化器中的关系模型中获取额外的列?

    I have Category and Article model Article有外键引用Category in my serializer由于 我可以在类别模型中获取名称列 str 方法 但我怎样才能得到其他列Category mode
  • 使用 Symfony2 / Symfony3 中的 FOSUserBundle 删除/替换用户名字段为电子邮件

    我只想使用电子邮件作为登录方式 我不想使用用户名 symfony2 symfony3 和 FOSUserbundle 可以吗 我在这里读到http groups google com group symfony2 browse thread
  • 不要扩展 React.Component

    创建 React 组件的 es6 语法是export default class ExampleComponent extends React Component 但是它仍然有效export default class ExampleCom
  • 如何为pytest命令指定几个标记

    Reading http doc pytest org en latest example markers html http doc pytest org en latest example markers html我看到了基于标记包含或
  • 限制 Java 中 HashMap 的最大大小

    我想限制 a 的最大尺寸HashMap对我正在实现的各种哈希算法进行度量 我查看了其中之一的负载因子HashMap的重载构造函数 HashMap int initialCapacity float loadFactor 我尝试在构造函数中将
  • 无法在 logback.xml 中使用 Spring 属性占位符

    我有一个使用 Logback 的 Spring Boot 控制台应用程序 所有属性 对于应用程序以及 Logback 都被外部化到类路径中的标准 application properties 文件中 这些属性可以在应用程序本身中很好地获取
  • 如何导入和使用.so文件

    请给我示例 代码 如何将 gccgo 生成的 so 文件导入到 main go 中 Go 尚不支持动态代码加载 即插件 有计划在未来添加支持 但目前尚未确定时间表 https docs google com document d 1nr T
  • 如何查看 numpy 广播对象?

    根据文档 http docs scipy org doc numpy user basics broadcasting html gt gt gt a np array 1 0 2 0 3 0 gt gt gt b np array 2 0
  • 正则表达式用于识别 Guid 后跟数字

    我有一个可以识别 Guid 的正则表达式 string pattern 0 9a fA F 8 0 9a fA F 4 0 9a fA F 4 0 9a fA F 4 0 9a fA F 12 我有一个可以识别数字的正则表达式 string
  • 如何在 Xamarin.Forms 中获取客户端设备的 MAC 地址?

    在我的客户端服务器解决方案中 我需要运行 Xamarin Forms 应用程序的前端设备的 MAC 地址 目前我只有一个条目 用户应该在其中输入运行应用程序的设备的 MAC 地址 主界面 我已经搜索过这个主题 发现iOS和Android对于
  • 如何将 AngularJS 变量传递给 Javascript?

    我正在构建一个带有模态窗口的 AngularJS Web 应用程序 在模态窗口中 我可以显示 JQuery Flot 实时图表 类似于 http people iola dk olau flot examples realtime html
  • 获取两个 NSDate 之间的准确时差?

    有什么办法可以找出两者之间的准确差异NSDate 我已经找到了解决方案 但它们不够准确 我需要考虑夏令时 不同月份有不同天数等事实 诸如 60 60 24 等计算分钟 小时和天的简单计算不会将它们考虑在内 假设我需要计算出现在时间之间的差异
  • 使用字典的 Protobuf-net 对象引用反序列化:引用跟踪对象在反序列化期间更改了引用

    我在尝试使用 protobuf net 序列化 反序列化复杂对象图时遇到一些问题 我正在开发一个遗留应用程序 我们正在使用 Net Remoting 将 GUI 客户端连接到 C 服务 由于使用默认值的对象图的序列化大小 我们发现海外用户的
  • 上传1GB或以上的文件

    上传大于 1 GB 的文件的最佳方式是什么 当前情况 我们正在使用 Flask 来部署网络服务器 我们必须上传大于 1 GB 的文件 以前我们只上传了几MB的文件 所以 这不是问题 但现在对于大于 1 GB 的文件 旧的上传方法不再可行 服
  • Qt 中带有进度回调的 CopyFileEx

    有人能给我一个在 Qt 中使用 CopyFileEx 和进度回调的工作示例吗 我发现了一些划痕并尝试合并它但没有成功 我什至无法将 CopyProgressRoutine 函数作为 CopyFileEx 的参数传递 因为我无法声明指向该函数
  • 加载 data.table 对象后直接使用 get(data.table) 生成新变量

    我正在尝试在 data table 中生成一个新变量 我生成 保存并再次加载该变量 加载后 我通过 get 间接寻址 data table 只要我之前不直接寻址它以创建变量 这对于生成新变量就不起作用 可能是某种环境问题 Generate
  • CDI 注入在 Servlet 中不起作用

    我真的需要你的帮助 我现在正在研究这个问题几周或几个月 对于这么长的帖子 我深表歉意 但我想尽可能准确地解释问题和我的设置 我的 JAVA EE 6 Web 应用程序主要包含 3 个 Servlet javax faces webapp F