1

我正在使用 Atmosphere 做一个 websocket 应用程序,我正在尝试在我自己的环境中重现聊天示例。我正在使用 TomEE 7 plus 服务器,并且该示例在其上运行良好。

我将 maven 依赖项添加到了大气运行时和 servlet 3.0,就像在示例中所做的那样

    <!-- PubSub dependencies -->
    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-runtime</artifactId>
        <version>2.3.3</version>
    </dependency>

    <!-- Spécification servlet 3.0 nécessaire pour atmosphere -->
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-servlet_3.0_spec</artifactId>
        <version>1.0</version>
    </dependency>

然后我将我的 servlet 放入 web.xml 文件中

<!-- Atmosphere Servlet -->
<servlet>
    <description>AtmosphereServlet</description>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <!-- limit classpath scanning to speed up starting, not mandatory -->
    <init-param>
        <param-name>org.atmosphere.cpr.packages</param-name>
        <param-value>my.package.web.websocket</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.interceptor.HeartbeatInterceptor.clientHeartbeatFrequencyInSeconds</param-name>
        <param-value>10</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/chat/*</url-pattern>
</servlet-mapping>

但是当我尝试AtmosphereResource在我的Chat课堂上注入时,我得到了这个错误:

 GRAVE: CDI Beans module deployment failed
org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.atmosphere.cpr.AtmosphereResource] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  resource, Bean Owner : [Chat, Name:null, WebBeans Type:MANAGED, API Types:[my.package.web.websocket.Chat,java.lang.Object], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:215)
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:192)
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:160)
    at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:846)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:652)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5416)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.atmosphere.cpr.AtmosphereResource] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  resource, Bean Owner : [Chat, Name:null, WebBeans Type:MANAGED, API Types:[my.package.wen.websocket.Chat,java.lang.Object], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
    at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:195)
    at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:960)
    at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:491)
    at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:422)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:202)
    ... 18 more

哈和另一个有用的信息我不使用ObjectMapperInjectable.java所以我没有META-INF/Services/org.atmosphere.inject.Injectable文件(它在示例中使用)。我的项目中有一个 beans.xml,我可以将我的业务服务注入Chat.java

我知道它找不到默认限定符,但我不明白为什么。

我是否需要为 AtmospherResource 接口指定限定符(我不这么认为)?没有默认实现吗?

有没有人解决了同样的问题?

谢谢

编辑

经过一些测试,它似乎来自 beans.xml。如果我将它添加到 META-INF/ 下的原始示例项目中,我会遇到同样的错误。

4

0 回答 0