我试图在本地appengine模拟器上运行我的代码,但我仍然收到类ServletInitializer不是javax.servlet.Servlet的错误信息 有来自启动的日志
Connected to server
2017-09-27 15:32:49.323:INFO:oejs.Server:main: jetty-9.3.18.v20170406
2017-09-27 15:32:53.756:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=3587ms
wrz 27, 2017 1:32:53 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: 2 Spring WebApplicationInitializers detected on classpath
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.7.RELEASE)
...
...
...
...
2017-09-27 13:33:03.777 [main] [32mINFO[m -o.s.b.StartupInfoLogger- Started ServletInitializer in 9.329 seconds (JVM running for 15.913)
2017-09-27 13:33:04.045 [main] [34mDEBUG[m -o.s.w.f.GenericFilterBean- Initializing filter 'provideJwtAuthTokenFilter'
2017-09-27 13:33:04.045 [main] [34mDEBUG[m -o.s.w.f.GenericFilterBean- Filter 'provideJwtAuthTokenFilter' configured successfully
2017-09-27 13:33:04.047 [main] [31mERROR[m -c.g.a.t.d.ApiProxyLocalImpl- javax.servlet.ServletContext log: unavailable
javax.servlet.UnavailableException: Servlet class com.blenge.blenge.ServletInitializer is not a javax.servlet.Servlet
at org.eclipse.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:522)
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:381)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:891)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1406)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1368)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:522)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:422)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:389)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.google.appengine.tools.development.jetty9.JettyContainerService.startContainer(JettyContainerService.java:346)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:284)
at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:87)
at com.google.appengine.tools.development.Modules.startup(Modules.java:105)
at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:274)
at com.google.appengine.tools.development.DevAppServerImpl.access$000(DevAppServerImpl.java:47)
at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:219)
at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:217)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:368)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:47)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:223)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:214)
我已经在教程和示例项目中创建了ServletInitializer类 https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/appengine-standard-java8/springboot-appengine-standard/src/main/java/com/example/appengine/demos/springboot/ServletInitializer.java
有我的build.gradle文件 https://gist.github.com/Mistic92/576d333df9da7d7efb3e833fd502e430
还有版本
中的gcloud sdkC:\Users\Lukasz>gcloud version
Google Cloud SDK 172.0.1
alpha 2017.09.15
app-engine-java 1.9.56
app-engine-python 1.9.60
beta 2017.09.15
bq 2.0.26
cloud-datastore-emulator 1.2.1
core 2017.09.21
datalab 20170818
gcloud
gsutil 4.27
kubectl
pubsub-emulator 2017.09.15
EDIT1: web.xml文件。另外,我得到警告,ServletInitializer不能分配给javax.servlet.Servlet。我该怎么办?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>blenge-backend</servlet-name>
<servlet-class>com.blenge.blenge.ServletInitializer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>blenge-backend</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:1)
如果你有一个web.xml,它应该指向servlet 3.1规范,而不是2.5 ... 缺少web.xml默认为3.1
答案 1 :(得分:0)
“class com.blenge.blenge.ServletInitializer不是javax.servlet.Servlet”似乎表明你的web.xml存在问题
另一种可能性是你有一个类加载器冲突。