问题
I'm having a problem with my CometD Application. It looks like its creating multiple instances of the Bayeux Server. My configuration Files look like the following and i'm using Web Sockets as Transport/GigaSpaces to deploy the Application (which uses its own embedded jetty Server). Just wondering if I've misconfigured something in the following setup?
WEB.XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>CometDApplication</display-name>
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
<init-param>
<param-name>jsonContext</param-name>
<param-value>org.cometd.server.JacksonJSONContextServer</param-value>
</init-param>
<init-param>
<param-name>transports</param-name>
<param-value>org.cometd.websocket.server.WebSocketTransport</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.openspaces.pu.container.jee.context.ProcessingUnitContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/META-INF/spring/pu.xml</param-value>
</context-param>
</web-app>
POM.XML:
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>bayeux-api</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-server</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-websocket-jetty</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>7.6.8.v20121106</version>
</dependency>
My Applcation Context File (pu.XML):
<bean id="Bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="0" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="Bayeux" />
</bean>
</list>
</property>
</bean>
<bean id="ContextExporter" class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="Bayeux" />
</entry>
</map>
</property>
</bean>
回答1:
You are indeed creating two instances of BayeuxServer
, one created by the CometdServlet
you define in web.xml
and one created by Spring.
Like stated in the CometD and Spring integration documentation, if you use Spring to initialize CometD, then your whole BayeuxServer
configuration must be in Spring.
Don't duplicate it in web.xml
.
Furthermore, since you define a <load-on-startup>
element, the CometdServlet
is initialized before Spring's ContextLoaderListener
, creating a BayeuxServer
instance before Spring gets the chance to create its own and export it.
Remove all <init-param>
from web.xml
, remove <load-on-startup>
and you should be good: the servlet will be lazily initialized and will find the Spring-created BayeuxServer
exported correctly, without creating an additional instance.
来源:https://stackoverflow.com/questions/16609341/duplicate-instance-of-bayeux-server-created