2013-04-27 60 views
0

JDK:1.7ServletContext沒有.createServlet方法?

我正在將第三方庫實現到我的應用程序中。我將[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) { 

    } 
} 

可能初步認識行家條目:

<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

你嘗試設置的servlet版本3+?

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.0.1</version> 
</dependency> 
相關問題