当前位置: 首页 > 知识库问答 >
问题:

Spring Boot应用程序已部署,但不会在Tomcat 8中启动

鲁杜吟
2023-03-14

我一直致力于将SpringBootWeb应用程序与Jenkins和Tomcat9集成在一起。当我在Eclipse中作为spring boot应用程序运行时,一切似乎都很好。

我现在正在建立Jenkins和一个测试/质量保证/展示和告知环境。当我试图在独立的Tomcat9环境中部署war时,我的应用程序无法正常启动。

我遵循了Spring Boot文档,让Eclipse为我完成了Tomcat集成的大部分工作。我还使用以下线程作为检查表。。。如何在tomcat服务器上部署spring boot web应用程序

我在我的开发机器和我的目标环境上得到了相同的堆栈跟踪,詹金斯和汤姆卡特9作为服务运行。

pom.xml

<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>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <maven.test.skip>true</maven.test.skip>
</properties>

<dependencies>
    <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.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>   
    </dependency>
    <dependency>  
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

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

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>${skipTests}</skipTests>
            </configuration>
        </plugin>
    </plugins>
</build>

应用性质

spring.datasource.url=jdbc:mysql://localhost:3305/myapp?useSSL=false
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL55Dialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

spring.mvc.view.prefix: /WEB-INF/
spring.mvc.view.suffix: .jsp
spring.messages.basename=validation

server.servlet.context-path=/

spring.jackson.serialization.wrap-root-value=false

WebApplication。JAVA


    @SpringBootApplication
    @EntityScan("com.myapp.model")
    public class WebApplication extends SpringBootServletInitializer implements ApplicationRunner{

        private static final Logger logger = LogManager.getLogger(WebApplication.class);

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(WebApplication.class);
        }

        @Override
        public void run(ApplicationArguments applicationArguments) throws Exception {
            logger.debug("Debugging log");
            logger.info("Info log");
            logger.warn("Hey, This is a warning!");
            logger.error("Oops! We have an Error. OK");
            logger.fatal("Snap! Fatal error. Please fix me.");
        }

        public static void main(String[] args) throws Exception {
            SpringApplication.run(WebApplication.class, args);
        }
    }

Tomcat中的错误日志

18-Mar-2020 18:43:38.712 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
    javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:157)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5140)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:493)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1642)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
        at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1590)
        at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:294)
        at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:212)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:211)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:666)
        at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:348)
        at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:53)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.StackOverflowError
        at java.lang.reflect.InvocationTargetException.<init>(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:110)
        at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:123)
        at org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass(StackLocatorUtil.java:55)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
        at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
        at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
        at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)

共有2个答案

邵伟泽
2023-03-14

尝试驱动程序类名:com.cj.mysql.jdbc.驱动程序

晏望
2023-03-14

这是由我的伐木罐冲突引起的...我注释了maven log4j2依赖项,并切换到Logback。

 类似资料:
  • 我正在使用maven,Eclipse。从Eclipse运行时一切都很好。但同样,如果部署在tomcat上,则返回http状态404。日志显示在类路径上未检测到Spring WebApplicationInitializer类型,但我正在使用web.xml。 如果有人能帮忙,我不知道这里有什么问题。筛选器和servlet映射没有问题。 securityFilter org.SpringFramewo

  • 完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。

  • 我部署了我的Rails应用程序,但当我打开它时,我在Web浏览器中收到此错误: 应用程序错误应用程序中发生错误,无法查看您的页面。如果您是应用程序所有者,请查看日志以了解详细信息。 以下是我的日志错误: 2018-03-19T04:48:12.360662 00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=获取路径=“/”主机=marmelade1。her

  • 我正在尝试将一个.ear应用程序部署到WildFly10.1Final。ear有2个嵌套的.war文件。war文件中没有“jboss-web.xml”文件。 信息[org.jboss.as.server.deployment.scanner](DeploymentScanner-Threads-1)WFLYDS0004:在部署目录中找到MyApp.ear。要触发部署,请创建一个名为myapp.ea

  • 我在Openshift上运行node.js应用时遇到了问题。 我已经设置了我的 openshift 项目来从 git 存储库中提取。 我的< code>server.listen调用如下: 拉取和构建工作正常。我可以在pod终端中看到我的应用程序正在运行,因为有一些输出指示这一点。我还可以看到和都不存在,因此端口默认为。 如果我进入pod的终端并执行< code > curl http://loc

  • 尝试在Heroku云中部署Spring Boot应用程序,但编译java应用程序时出现错误,但在我的本地计算机中运行良好。