用tomcat启动spring-boot
2021-03-06 05:30
标签:conf component over override style boot packages nbu work 两种做法 修改Appcation.java文件 或者添加一个文件ServletInitializer.java 可以正常进入网页 用tomcat启动spring-boot 标签:conf component over override style boot packages nbu work 原文地址:https://www.cnblogs.com/YC-L/p/14300601.htmlpackage 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);
}
}
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);
}
}