这篇文章主要介绍了SpringBoot Tomcat启动实例代码详解,需要的朋友可以参考下
废话不多了,具体内容如下所示:
Application configuration class: @SpringBootApplication public<i style="color:transparent">来源gaodai$ma#com搞$$代**码)网</i> class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ServletInitializer.class); } public static void main(String[] args) throws Exception { SpringApplication.run(ServletInitializer.class, args); } }
注意: 启动类放在项目的包的最外层最好,这样可以扫描到所有的包路径。
controller:
@Controller public class BootController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(BootController.class, args); } }
pom
4.0.0cn.creditease.springbootspringbootwar1.0Maven Webapphttp://maven.apache.org UTF-8UTF-81.71.77.0.67 org.springframework.bootspring-boot-starter-parent1.4.1.RELEASE org.springframework.bootspring-boot-starter-web org.springframework.bootspring-boot-starter-tomcatprovided org.springframework.bootspring-boot-starter-testtest spring-releasesSpring Releaseshttp://repo.spring.io/libs-release-local true
注意:如果想用tomcat7启动要制定你的tomcat版本号。
server: port: 8080 spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp
项目
总结
以上就是SpringBoot Tomcat启动实例代码详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!