zoukankan      html  css  js  c++  java
  • springboot应用在tomcat中运行

    1.将打包方式改成war,因为如果是java -jar xx.jar方式运行,一定是jar包

     <packaging>war</packaging>
    

    2.添加tomcat的依赖,但是注意作用域(scope)

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

    3.配置JavaBean,就是要继承SpringBootInitializer类,重写configure方法

    public class ServletInitializer extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(SpringBootApplication.class);
        }
    
    }
    
    

    4.用tomcat8以上,经验:用tomcat7及以下时,会报如下 错:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path
    
    
  • 相关阅读:
    Jenkins
    python爬虫
    git分布式版本控制
    CKA考试认证总结
    gitlab-ci 工具链
    gitlab-ci 模板库实践
    gitlab-cicd
    gitlab配置文件gitlab.rb详解
    局部变量表中的slot简述
    JVM系统线程类型
  • 原文地址:https://www.cnblogs.com/Lyn4ever/p/11495048.html
Copyright © 2011-2022 走看看