SpringBoot Tomcat启动实例代码详解

网友投稿 189 2023-04-07


SpringBoot Tomcat启动实例代码详解

废话不多了,具体内容如下所示:

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

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

cn.creditease.springboot

springboot

war

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-parent

1.4.1.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-tomcat

provided

org.springframework.boot

spring-boot-starter-test

test

spring-releases

Spring Releases

http://repo.spring.io/libs-release-local

true

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

cn.creditease.springboot

springboot

war

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-parent

1.4.1.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-tomcat

provided

org.springframework.boot

spring-boot-starter-test

test

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启动实例代码详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java 中POI 导入EXCEL2003 和EXCEL2007的实现方法
下一篇:Commons beanutils组件简介
相关文章

 发表评论

暂时没有评论,来抢沙发吧~