废话不多了,具体内容如下所示:
Application configuration class:
@SpringBootApplication
public 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.0 cn.creditease.springboot springbootwar 1.0 Maven Webapp http://maven.apache.org UTF-8 UTF-8 1.7 1.7 7.0.67 org.springframework.boot spring-boot-starter-parent1.4.1.RELEASE org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-tomcatprovided org.springframework.boot spring-boot-starter-testtest spring-releases Spring Releases http://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启动实例代码详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!



