我正在使用Spring Boot + App Engine构建一个简单的Web应用程序。 我遵循了getting started github page中建议的指导方针,并且在我尝试实现一个简单的过滤器之前,一切工作正常:
public class AuthFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
log.info("TESST");
}
}
以简单的servlet方式配置了web.xml页面:
<?xml version="1.0" encoding="UTF-8"?>
<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"
version="3.1">
<filter>
<filter-name>AuthFilter</filter-name>
<filter-class>eu.project.docscatalog.filters.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
(我也尝试了@Component批注,就像您通常在spring应用程序中一样)
当我使用mvn appengine启动应用程序时:运行Web服务器启动,但出现以下错误消息:
[INFO] GCLOUD: 2019-06-03 10:28:07.956:WARN:oejw.WebAppContext:main: Failed startup of context c.g.a.t.d.j.DevAppEngineWebAppContext@a85644c{/,file:///C:/Users/Pierluigi/Desktop/source/docs-catalog/target/docs-catalog-1-0-0/,UNA
VAILABLE}{C:\Users\Pierluigi\Desktop\source\docs-catalog\target\docs-catalog-1-0-0}
[INFO] GCLOUD: java.lang.AbstractMethodError
[INFO] GCLOUD: at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:136)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$0(ServletHandler.java:750)
[INFO] GCLOUD: at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:744)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:368)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:852)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:278)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.start(Server.java:415)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.doStart(Server.java:382)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at com.google.appengine.tools.development.jetty9.JettyContainerService.startContainer(JettyContainerService.java:343)
[INFO] GCLOUD: at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:283)
[INFO] GCLOUD: at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
[INFO] GCLOUD: at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:87)
[INFO] GCLOUD: at com.google.appengine.tools.development.Modules.startup(Modules.java:105)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:282)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerImpl.access$000(DevAppServerImpl.java:47)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:223)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:221)
[INFO] GCLOUD: at java.security.AccessController.doPrivileged(Native Method)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:221)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:404)
[INFO] GCLOUD: at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:45)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:257)
[INFO] GCLOUD: at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:248)
该过滤器不起作用,我认为这可能与所提供的tomcat有关,并且是由某些重复的依赖项引起的,但是我找不到引起此问题的原因。我的pom包含以下依赖项:
<dependencies>
<!--Spring boot components-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-data-datastore</artifactId>
</dependency>
<!--Standard dep-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<!--Provided-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>provided</scope>
</dependency>
<!--Test related-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
有人知道发生了什么事吗? 我真的要感谢任何帮助的人:)
答案 0 :(得分:0)
我知道了。
我没有正确遵循getting started page。
我必须从spring-boot-starter-web中排除spring-boot-starter-tomcat并包括servlet-api。
感谢@Saheb将我指向正确的方向:)
答案 1 :(得分:0)
这篇文章可能会帮助遇到如下类似问题的人。
我遇到了类似的错误java.lang.AbstractMethodError,但没有提到真正的原因。在App Engine灵活环境中部署Spring Boot应用程序时发生此错误。 原因是slf4j库。
java.lang.AbstractMethodError: null
[INFO] GCLOUD: at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:136)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$0(ServletHandler.java:750)
[INFO] GCLOUD: at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:744)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:369)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:854)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:278)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:192)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:510)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:153)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:172)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:430)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:65)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:145)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:598)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:240)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:167)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.start(Server.java:418)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:119)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.doStart(Server.java:382)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1797)
[INFO] GCLOUD: at java.security.AccessController.doPrivileged(Native Method)
[INFO] GCLOUD: at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1746)
[INFO] GCLOUD:
[INFO] GCLOUD: Exception in thread "main" java.lang.AbstractMethodError
[INFO] GCLOUD: at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:136)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$0(ServletHandler.java:750)
[INFO] GCLOUD: at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
[INFO] GCLOUD: at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:744)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:369)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:854)
[INFO] GCLOUD: at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:278)
[INFO] GCLOUD: at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:192)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:510)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:153)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:172)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:430)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:65)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392)
[INFO] GCLOUD: at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:145)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:598)
[INFO] GCLOUD: at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:240)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:167)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.start(Server.java:418)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:119)
[INFO] GCLOUD: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[INFO] GCLOUD: at org.eclipse.jetty.server.Server.doStart(Server.java:382)
[INFO] GCLOUD: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[INFO] GCLOUD: at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1797)
[INFO] GCLOUD: at java.security.AccessController.doPrivileged(Native Method)
[INFO] GCLOUD: at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1746)