idea中使⽤tomcat⽅式启动springboot项⽬
Spring boot 的main ⼊⼝启动⽅式相信都会⽤,直接运⾏main直接就启动了,但是往往这种⽅式并不是最佳的启动⽅式,⽐如运维的层⾯更希望调整tomcat的调优参数,⽽只使⽤嵌⼊启动⽅式很难做到这些。所以使⽤tomcat⽅式启动spring boot就⽐较重要。
1、去tomcat 官⽹下载 tomcat ⽂件,然后解压.
2、idea中,配置启动
3、gradle or maven 配置
<packaging>war</packaging>
or
apply plugin: "war"
4、增加tomcat启动调⽤spring boot初始化⼊⼝:
public class ServletInitializer extends SpringBootServletInitializer {
private Logger logger = Logger(ServletInitializer.class);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
logger.info("starting spring boot initializer ......");
return application.sources(MainApplication.class);
}
}
or
ample.demo;
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;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
spring frameworkSpringApplication.run(Application.class, args);
}
}
5、start runing
搞定!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论