Spring Boot Embeded Tomcat无法启动

时间:2016-09-26 06:40:24

标签: spring maven tomcat spring-boot

我正在使用Spring Boot构建系统。我使用Spring Tools Suite作为IDE,我可以使用Spring Tool Suite构建和运行程序作为Spring Boot App而没有任何问题。但是,当我通过命令" mvn package"来构建maven并在target / my-app.jar下运行生成的jar文件时,嵌入的tomcat无法启动。错误如下:

  

org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常是org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat           在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)〜[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]           在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.SpringApplication.run(SpringApplication.java:313)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在com.jdescript.JdeScriptApplication.main(JdeScriptApplication.java:23)[classes!/:0.0.1]           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_91]           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_91]           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_91]           在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_91]           在org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)[jde-script-0.0.1.jar:0.0.1]           在org.springframework.boot.loader.Launcher.launch(Launcher.java:87)[jde-script-0.0.1.jar:0.0.1]           在org.springframework.boot.loader.Launcher.launch(Launcher.java:50)[jde-script-0.0.1.jar:0.0.1]           在org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:525)[jde-script-0.0.1.jar:0.0.1]   引起:org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat           在org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:116)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer。(TomcatEmbeddedServletContainer.java:83)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:530)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:176)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           ...省略了16个常用帧   引起:org.apache.catalina.LifecycleException:无法启动组件[StandardServer [-1]]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.startup.Tomcat.start(Tomcat.java:356)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]           ...省略了21个常用帧   引起:org.apache.catalina.LifecycleException:无法启动组件[StandardService [Tomcat]]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           ...省略了23个常见帧   引起:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat]]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           ...省略了25个常用帧   引起:org.apache.catalina.LifecycleException:子容器在启动期间失败           在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)~ [tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)〜[tomcat-embed-core-8.5.4.jar!/:8.5.4]           ...省略了27个常见帧

我的pom.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myapp</groupId>
    <artifactId>my-app</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>MyApp</name>
    <description>My App</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

任何建议都将不胜感激!

2 个答案:

答案 0 :(得分:1)

我已经弄明白了。我的系统是与第三方企业系统交互,我的系统依赖于来自第三方系统的一些JAR文件。所以我有&#34; -Dloader.path&#34;指向第三方JAR文件的目录。其中一个JAR文件j2ee.jar与tomcat冲突。如果我从&#34; -Dloader.path&#34;中删除j2ee.jar文件,Tomcat将启动。

无论如何,再次感谢你的所有建议!

答案 1 :(得分:0)

正如Deinum在评论中所说。

您的jar中没有包含嵌入式tomcat依赖项,因为您已将tomcat依赖作用域提供为&#34; runtime&#34;。删除范围声明,该声明应启用&#34;编译&#34;范围默认。然后,您的jar应该包含启动嵌入式tomcat容器所需的依赖项。