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

时间:2018-05-24 18:25:19

标签: java spring-boot jetty

在jetty中运行我的内置war文件时收到以下错误:

>>> 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)           

bubbleshadow2.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>

倍率-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>

Application.java

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扩展将是正确的方法。

1 个答案:

答案 0 :(得分:0)

标准Servlet规则适用于此。

Dim files, i As Integer Dim dailogbox As FileDialog Dim mainWorkbook, sourceWorkbook As Workbook Dim sheets As Worksheet Set mainWorkbook = Application.ActiveWorkbook Set dailogbox = Application.FileDialog(msoFileDialogFilePicker) dailogbox.AllowMultiSelect = True files = dailogbox.Show For i = 1 To dailogbox.SelectedItems.Count Workbooks.Open dailogbox.SelectedItems(i) Set sourceWorkbook = ActiveWorkbook For Each sheets In sourceWorkbook.Worksheets sheets.Copy after:=mainWorkbook.Sheets(mainWorkbook.Worksheets.Count) Next tempWorkSheet sourceWorkbook.Close Next i 不会从net.firezeal.bubbleshadow.Application延伸,因此无法在网络描述符中将其定义为javax.servlet.Servlet

通常&#34;应用程序&#34; (在Spring-Boot术语中,甚至是Jax-RS / Jersey术语)是一种配置,在标准servlet上看作<servlet-class>值,或者在Web描述符之外使用配置文件声明。