Spring Boot 未在 Eclipse 中与 Tomcat 一起运行
Posted
技术标签:
【中文标题】Spring Boot 未在 Eclipse 中与 Tomcat 一起运行【英文标题】:Spring boot not running with Tomcat in Eclipse 【发布时间】:2018-12-01 07:16:57 【问题描述】:我正在尝试使用 Tomcat 使用 Eclipse 调试 Spring Boot 项目,但是当我尝试运行它时总是收到同样的错误:
Jun 21, 2018 5:22:32 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.j2ee.server:report-engine' did not find a matching property.
[...]
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/vitor/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Jun 21, 2018 5:22:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8181"]
Jun 21, 2018 5:22:33 PM org.apache.tomcat.util.net.NioselectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jun 21, 2018 5:22:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Jun 21, 2018 5:22:33 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jun 21, 2018 5:22:33 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2006 ms
Jun 21, 2018 5:22:33 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 21, 2018 5:22:33 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.50
Jun 21, 2018 5:22:40 PM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[...]
Jun 21, 2018 5:22:40 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 21, 2018 5:22:56 PM org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
[...]
Jun 21, 2018 5:22:57 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 21, 2018 5:22:57 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/report-engine]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/report-engine]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
... 6 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/FacesException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2475)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:855)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1304)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1163)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2475)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:855)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1304)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1163)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1315)
at org.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:647)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:108)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5311)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 6 more
Jun 21, 2018 5:22:57 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:641)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 6 more
Jun 21, 2018 5:22:57 PM org.apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.startup.Catalina.start(Catalina.java:641)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:789)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
... 11 more
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8181"]
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
Jun 21, 2018 5:22:57 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8181"]
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["http-nio-8181"]
java.lang.NullPointerException
at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:315)
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:491)
at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:896)
at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:879)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.startup.Catalina.start(Catalina.java:645)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
Jun 21, 2018 5:22:57 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
java.lang.NullPointerException
at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:315)
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:491)
at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:896)
at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:879)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.startup.Catalina.start(Catalina.java:645)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:349)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:483)
该项目使用 Gradle,它是一个 REST 服务。我尝试了很多我在网上找到的方法,但直到现在都没有奏效。
另外,如果我使用gradle bootRun
从终端启动它,同样的项目也可以工作,但是我需要从 Eclipse 启动它来调试它。
【问题讨论】:
您是否安装并运行了 gradle 工具(Buildship)? Gradle 任务视图是否不允许您调用bootRun
?
@nitind 是的,我确实已经安装并工作了。不,Gradle Tasks 确实让我调用 bootRun
,它就像在终端中一样工作。
【参考方案1】:
如果你愿意。 如果您的项目是 Maven 项目。
从 maven 项目开始,然后在命令行中运行项目根目录中的“mvn eclipse:eclipse”。 从那里将项目导入为现有的 Maven 项目。
你可以确保将tomcat添加到你的pom中,像这样
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
然后我们将使用 mvn 而不是 gradle 构建 mvn clean package -DSkipTests=true
然后确保包含一个应用程序类来启动所有内容: 像这样:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ThinkdeepIntegrationApplication
public static void main(String[] args)
SpringApplication.run(ThinkdeepIntegrationApplication.class, args);
希望这可能会有所帮助。不幸的是,我过去没有使用 gradle 做任何事情,这就是我推荐这种方式的原因
【讨论】:
当我使用 gradle 时,我已经完成了我认为已经完成的工作,但它不起作用(这只是将第一步替换为:运行 @987654323 @ 并将这一行添加到 build.gradle 的依赖项中:compile 'org.springframework.boot:spring-boot-starter-web'
)。以上是关于Spring Boot 未在 Eclipse 中与 Tomcat 一起运行的主要内容,如果未能解决你的问题,请参考以下文章
Spring/Boot - JWT 未在 GET 请求中获取
bootstrap.yml 未在 Spring Boot 2 中加载