气氛+弹簧+球衣配置问题

时间:2016-03-09 17:08:52

标签: spring asynchronous jersey autowired atmosphere

我无法正确配置弹簧和平针织物的气氛。

这是我的web.xml:

<servlet>
    <servlet-name>spring </servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>spring </servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.mypackage.api</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.jersey.servlet-mapping</param-name>
        <param-value>/api/*</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>/n/*</url-pattern>
</servlet-mapping>

Jersey在使用

时处理对/ api / *的所有请求
org.atmosphere.cpr.AtmosphereServlet 

但是我无法自动调试我的spring组件,因此我将servlet类更改为:

org.atmosphere.spring.bean.AtmosphereSpringServlet

如此链接中所示:https://github.com/Atmosphere/atmosphere/wiki/Configuring-Atmosphere-as-a-Spring-Bean

我配置了我的ApplicationContext:

<bean id="framework" class="org.atmosphere.cpr.AtmosphereFramework">
    <constructor-arg index="0" value="false"/>
    <constructor-arg index="1" value="false"/>
</bean>

<bean class="org.atmosphere.spring.bean.AtmosphereSpringContext">
    <property name="config">
        <map>
            <entry key="org.atmosphere.cpr.broadcasterClass" value="org.atmosphere.cpr.DefaultBroadcaster"/>                                
            <entry key="org.atmosphere.cpr.broadcasterLifeCyclePolicy" value="IDLE_DESTROY"/>                                  
        </map>
    </property>
</bean>

<!--Add an Atomsphere handler (if necessary) -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" ref ="framework"/>
    <property name="targetMethod" value="addAtmosphereHandler"/>
    <property name="arguments">
        <list>
            <value>/n/*</value>
            <bean class="org.mypackage.api.ChatHandler"/>
        </list>
    </property>
</bean>

但后来我收到了这个错误:

java.lang.NoSuchMethodException: org.atmosphere.cpr.AtmosphereFramework.addAtmosphereHandler(java.lang.String, org.mypackage.api.ChatHandler)

这是我的ChatHandler类:

Path("/chat")

@AtmosphereService(broadcaster = JerseyBroadcaster.class) 公共类ChatHandler {

/**
 * Suspend the response without writing anything back to the client.
 *
 * @return a white space
 */
@Suspend(contentType = "application/json", listeners = {OnDisconnect.class})
@GET
public String suspend() {

    return "";
}

/**
 * Broadcast the received message object to all suspended response. Do not write back the message to the calling connection.
 *
 * @param author
 * @param message a {@link Message}
 * @return a {@link Response}
 */
@Broadcast(writeEntity = false)
@POST
@Produces("application/json")
public String broadcast(@FormParam("author")String author, @FormParam("message")String message) {
    return "hello"+author+" message :"+message;
}

public static final class OnDisconnect extends AtmosphereResourceEventListenerAdapter {
    private final Logger logger = LoggerFactory.getLogger(ChatHandler.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public void onDisconnect(AtmosphereResourceEvent event) {
        if (event.isCancelled()) {
            logger.info("Browser {} unexpectedly disconnected", event.getResource().uuid());
        } else if (event.isClosedByClient()) {
            logger.info("Browser {} closed the connection", event.getResource().uuid());
        }
    }
}

}

我的pom xml对于相关部分来说是这样的:

<dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-runtime</artifactId>
        <version>2.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-jersey</artifactId>
        <version>2.4.3</version>
    </dependency>

    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-spring</artifactId>
        <version>2.4.2</version>
    </dependency>
    <dependency>
        <groupId>eu.infomas</groupId>
        <artifactId>annotation-detector</artifactId>
        <version>3.0.5</version>
    </dependency>

春季版是:4.2.3

我已经完成了大部分主题,但无法找到答案。 我希望能够通过泽西使用@Annotations(暂停,广播,简历)并保持Spring的自动装配可能性。

提前致谢

0 个答案:

没有答案