栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot Tomcat启动实例代码详解

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/144397.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号