ServletContext没有.createServlet方法?

时间:2013-04-27 12:49:11

标签: spring grizzly

JDK:1.7

我正在努力在我的应用程序中实现第三方库。我将[WebappContext][1]传递给下面的AtmosphereModule()。进入后,它最终达到以下方法并抛出NoSuchMethodError异常。我有点难过。我正在使用

private void installAtmosphere(ServletContext context, Options options) {
    AtmosphereServlet servlet = null;
    try {
        servlet = context.createServlet(AtmosphereServlet.class);  //ERROR
    } catch (ServletException e) {
        throw new IllegalStateException(e);
    }

我的课程:

import com.production.ApplicationContextProvider;
import com.production.workflow.process.approval.ApprovalSocketHandler;
import com.github.flowersinthesand.portal.App;
import com.github.flowersinthesand.portal.Bean;
import com.github.flowersinthesand.portal.Options;
import com.github.flowersinthesand.portal.atmosphere.AtmosphereModule;
import com.github.flowersinthesand.portal.spring.SpringModule;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * Created with IntelliJ IDEA.
 */
@WebListener
public class SocketInitializer implements ServletContextListener {

    public static App app;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        AutowireCapableBeanFactory beanFactory = ApplicationContextProvider.getApplicationContext().getAutowireCapableBeanFactory();
        app =  new App(new Options().url("/socket/workstation/approval").packageOf(this), new AtmosphereModule(servletContextEvent.getServletContext()), new SpringModule(beanFactory));
        app.bean(ApprovalSocketHandler.class).init();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}

可能的相关maven条目:

<properties>
    <grizzly-version>2.2.21</grizzly-version>
    <jersey-version>1.17.1</jersey-version>
    <slf4j-version>1.7.5</slf4j-version>
    <javax-version>6.0</javax-version>
    <java-version>1.6</java-version>
    <org.springframework-version>3.1.2.RELEASE</org.springframework-version>
    <atmosphere.version>1.0.0.beta5</atmosphere.version>
</properties>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

<!-- Grizzly -->

<dependency>
    <groupId>org.glassfish.grizzly</groupId>
    <artifactId>grizzly-websockets-server</artifactId>
    <version>${grizzly-version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.grizzly</groupId>
    <artifactId>grizzly-http-servlet</artifactId>
    <version>${grizzly-version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.grizzly</groupId>
    <artifactId>grizzly-comet</artifactId>
    <version>${grizzly-version}</version>
</dependency>

1 个答案:

答案 0 :(得分:1)

您是否尝试将servlet版本设置为3 +?

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
 </dependency>