Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;缺少ServletContext“;使用SpringBootWeb应用程序(版本1.5.4)进行Comed配置(版本3.1.2)_Java_Spring Boot_Cometd - Fatal编程技术网

Java &引用;缺少ServletContext“;使用SpringBootWeb应用程序(版本1.5.4)进行Comed配置(版本3.1.2)

Java &引用;缺少ServletContext“;使用SpringBootWeb应用程序(版本1.5.4)进行Comed配置(版本3.1.2),java,spring-boot,cometd,Java,Spring Boot,Cometd,使用中所述的底漆时,一切正常。Spring、CometD和Jetty的版本协调一致 现在,我(一个SpringBoot新手)想用CometD(版本3.1.2)安装一个SpringBootWeb应用程序(版本1.5.4)。我还希望通过注释进行配置,而不使用前面提到的web.xml 为此,我在一个Spring Boot项目中找到了github项目“Livechat”,它为Comet提供了一个“如何准备WebsocketConfiguration的示例”——我无法让它运行 我所有的尝试都失败了,无法让

使用中所述的底漆时,一切正常。Spring、CometD和Jetty的版本协调一致

现在,我(一个SpringBoot新手)想用CometD(版本3.1.2)安装一个SpringBootWeb应用程序(版本1.5.4)。我还希望通过注释进行配置,而不使用前面提到的web.xml

为此,我在一个Spring Boot项目中找到了github项目“Livechat”,它为Comet提供了一个“如何准备WebsocketConfiguration的示例”——我无法让它运行

我所有的尝试都失败了,无法让一个简单的spring启动应用程序使用带注释的Comed配置运行

因此,我请求帮助设置Spring引导应用程序:

  • 基于1.5.4版
  • CometD(版本3.1.2)
  • 同时使用:jetty 9.x和tomcat(如果可能)
  • 使用注释而不是web.xml

以下是我在测试中遇到的主要异常:缺少ServletContext

Caused by: java.lang.IllegalArgumentException: Missing ServletContext
at org.cometd.websocket.server.WebSocketTransport.init(WebSocketTransport.java:60) ~[cometd-java-websocket-javax-server-3.1.2.jar:na]
at org.cometd.server.BayeuxServerImpl.initializeServerTransports(BayeuxServerImpl.java:255) ~[cometd-java-server-3.1.2.jar:na]
at org.cometd.server.BayeuxServerImpl.doStart(BayeuxServerImpl.java:135) ~[cometd-java-server-3.1.2.jar:na]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-util-9.4.6.v20170531.jar:9.4.6.v20170531]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1695) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 29 common frames omitted
WebApplication.java

@ComponentScan
@SpringBootApplication
@EnableScheduling
public class WebApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(WebApplication.class, args);
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <cometd-version>3.1.2</cometd-version>
        <jetty-version>9.4.6.v20170531</jetty-version>
    </properties>

    <dependencies>

        <!-- Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- JSP and JSTL SUPPORT -->
        <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <scope>provided</scope>
        </dependency>

        <!-- Cometd dependencies -->
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>bayeux-api</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.javascript</groupId>
            <artifactId>cometd-javascript-jquery</artifactId>
            <version>${cometd-version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-server</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-websocket-javax-server</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-annotations</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-oort</artifactId>
            <version>${cometd-version}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util-ajax</artifactId>
            <version>${jetty-version}</version>
        </dependency>

        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>apache-jstl</artifactId>
          <version>${jetty-version}</version>
          <type>pom</type>
        </dependency>
        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>apache-jsp</artifactId>
          <version>${jetty-version}</version>
          <type>jar</type>
    </dependency>       

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/cometd-primer</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>
ComedConfiguration.java(如“Comed参考书”第9.3.3.26章“基于注释的Spring配置”所述):

pom.xml

@ComponentScan
@SpringBootApplication
@EnableScheduling
public class WebApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(WebApplication.class, args);
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <cometd-version>3.1.2</cometd-version>
        <jetty-version>9.4.6.v20170531</jetty-version>
    </properties>

    <dependencies>

        <!-- Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- JSP and JSTL SUPPORT -->
        <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <scope>provided</scope>
        </dependency>

        <!-- Cometd dependencies -->
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>bayeux-api</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.javascript</groupId>
            <artifactId>cometd-javascript-jquery</artifactId>
            <version>${cometd-version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-server</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-websocket-javax-server</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-annotations</artifactId>
            <version>${cometd-version}</version>
        </dependency>
        <dependency>
            <groupId>org.cometd.java</groupId>
            <artifactId>cometd-java-oort</artifactId>
            <version>${cometd-version}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util-ajax</artifactId>
            <version>${jetty-version}</version>
        </dependency>

        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>apache-jstl</artifactId>
          <version>${jetty-version}</version>
          <type>pom</type>
        </dependency>
        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>apache-jsp</artifactId>
          <version>${jetty-version}</version>
          <type>jar</type>
    </dependency>       

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/cometd-primer</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

4.0.0
com.example
演示
0.0.1-快照
战争
演示
SpringBoot的演示项目
org.springframework.boot
spring启动程序父级
1.5.4.1发布
UTF-8
UTF-8
1.8
3.1.2
9.4.6.v20170531
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧靴起动器码头
org.springframework.boot
弹簧起动试验
测试
javax.servlet
jstl
假如
org.cometd.java
巴约api
${cometd version}
org.cometd.javascript
cometd javascript jquery
${cometd version}
战争
org.cometd.java
cometd java服务器
${cometd version}
org.cometd.java
CometdJavaWebSocket javax服务器
${cometd version}
org.cometd.java
cometd java注释
${cometd version}
org.cometd.java
彗星爪哇奥尔特
${cometd version}
org.eclipse.jetty
码头
${jetty版本}
org.eclipse.jetty
码头
${jetty版本}
org.eclipse.jetty
ApacheJSTL
${jetty版本}
聚甲醛
org.eclipse.jetty
apache jsp
${jetty版本}
罐子
org.slf4j
slf4j简单
1.7.25
org.springframework.boot
springbootmaven插件
10
/彗星底漆

能够复制,看起来像是初始化排序问题。我正在研究这个问题,请继续关注。另请参阅:Spring boot在解决bean的依赖注入后启动嵌入式Servlet容器,因此,
ServletContext
还不可用。这与普通Spring不同(以及您参考的Comet文档)因为您通常在Spring之前启动Servlet容器,因此,
ServletContext
。我不知道是否有办法让Spring Boot在嵌入式Servlet容器启动后解析bean。非常感谢您的关注。上面的链接自1.5年以来一直没有得到答案。我是否应该停止尝试运行Sspring Boot应用程序?你认为有机会让它运行吗?还有,livechat项目——我在问题中提到过——怎么可能使用旧版本的spring、Comed和jetty运行spring Boot应用程序?