簡體   English   中英

使用SpringBootServletInitializer:應用程序不是javax.servlet.Servlet

[英]Using SpringBootServletInitializer: Application is not a javax.servlet.Servlet

在碼頭內運行構建的戰爭文件時,我收到以下錯誤:

>>> cd $JETTY_BASE; java -jar $JETTY_HOME/start.jar

2018-05-24 11:02:05.024:INFO::main: Logging initialized @386ms to org.eclipse.jetty.util.log.StdErrLog                                               
2018-05-24 11:02:05.201:INFO:oejs.Server:main: jetty-9.4.9.v20180320; built: 2018-03-20T05:21:10-07:00; git: 1f8159b1e4a42d3f79997021ea1609f2fbac6de5$
 jvm 1.8.0_172-b11                                                                                                                                   
2018-05-24 11:02:05.214:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///Users/dlynch/Srv/bubbleshadow/webapps/] at interval 1       
2018-05-24 11:02:05.590:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet         
2018-05-24 11:02:05.596:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0                                                             
2018-05-24 11:02:05.596:INFO:oejs.session:main: No SessionScavenger set, using defaults                                                              
2018-05-24 11:02:05.597:INFO:oejs.session:main: Scavenging every 600000ms                                                                            
2018-05-24 11:02:05.604:WARN:oejshC.ROOT:main: unavailable                                         
javax.servlet.UnavailableException: Servlet class net.firezeal.bubbleshadow.Application is not a javax.servlet.Servlet                               
        at org.eclipse.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:553)           

bubblehadow2.xml

<Configure id="bubbleshadow" class="org.eclipse.jetty.webapp.WebAppContext">

  <Set name="contextPath">/</Set>
  <Set name="war"><Property name="jetty.webapps" default="."/>/bubbleshadow2.war</Set>

  <Set name="extractWAR">true</Set>
  <Set name="copyWebDir">false</Set>
  <Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
  <Set name="overrideDescriptor"><Property name="jetty.webapps" default="."/>/bubbleshadow2.d/override-web.xml</Set>

</Configure>

overlay-web.xml

<web-app>
   xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
   metadata-complete="false"
   version="3.1">

  <servlet>
    <servlet-name>bubbleshadow2</servlet-name>
    <servlet-class>net.firezeal.bubbleshadow.Application</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>bubbleshadow2</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

應用程序

package net.firezeal.bubbleshadow;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

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

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

  @Bean
  public StartupRunner schedulerRunner() {
    return new StartupRunner();
  }
}

我確定為什么我的“ Application”類不被視為javax.servlet.Servlet,因為我認為從SpringBootServletInitializer進行擴展將是正確的方法。

標准Servlet規則在這里適用。

net.firezeal.bubbleshadow.Application不能從javax.servlet.Servlet擴展,因此不能在Web描述符中定義為<servlet-class>

通常,“應用程序”(以Spring-Boot術語,甚至是Jax-RS / Jersey術語)是一種配置,在標准Servlet上顯示為<init-param>值,或者使用Web描述符外部的配置文件聲明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM