zoukankan      html  css  js  c++  java
  • 用tomcat启动spring-boot

    两种做法

    修改Appcation.java文件

    package com.techny.lianmai;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.ComponentScan;
    
    @SpringBootApplication
    @ComponentScan(basePackages = {"com.techny.lianmai.*"})  //指定扫描包路径
    public class LianmaiApplication extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(LianmaiApplication.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(LianmaiApplication.class, args);
        }
    
    }

    或者添加一个文件ServletInitializer.java

    package com.techny.lianmai;
    
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    
    public class ServletInitializer extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(LianmaiApplication.class);
        }
    
    }

    可以正常进入网页

    论读书
    睁开眼,书在面前
    闭上眼,书在心里
  • 相关阅读:
    JAVA 接口与抽象类(interface与abstract)的区别
    接口测试的测试点
    HTTP协议首部及Fiddler工具工作原理
    Android自动化测试AppiumLibrary库关键字
    蔬菜水果购买记
    健胃饮食
    榨汁机食谱
    随机权值平均
    周鸿祎IOT发布会思考
    Bilinear CNN与 Randomly Wired Neural Network
  • 原文地址:https://www.cnblogs.com/YC-L/p/14300601.html
Copyright © 2011-2022 走看看