码迷,mamicode.com
首页 > 编程语言 > 详细

用tomcat启动spring-boot

时间:2021-01-20 12:07:41      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:conf   component   over   override   style   boot   packages   nbu   work   

两种做法

修改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);
    }

}

可以正常进入网页

用tomcat启动spring-boot

标签:conf   component   over   override   style   boot   packages   nbu   work   

原文地址:https://www.cnblogs.com/YC-L/p/14300601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!