SpringBoot Tomcat啟動實(shí)例代碼詳解
廢話不多了,具體內(nèi)容如下所示:
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); } }
注意: 啟動類放在項(xiàng)目的包的最外層最好,這樣可以掃描到所有的包路徑。
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.creditease.springboot</groupId> <artifactId>springboot</artifactId> <packaging>war</packaging> <version>1.0</version> <name>Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project_charset>UTF-8</project_charset> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <tomcat.version>7.0.67</tomcat.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <repositories> <repository> <id>spring-releases</id> <name>Spring Releases</name> <url>http://repo.spring.io/libs-release-local</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </project>
注意:如果想用tomcat7啟動要制定你的tomcat版本號。
server: port: 8080 spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp
項(xiàng)目
總結(jié)
以上所述是小編給大家介紹的SpringBoot Tomcat啟動實(shí)例代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- SpringBoot中如何啟動Tomcat流程
- SpringBoot應(yīng)用部署到Tomcat中無法啟動的解決方法
- Spring Boot啟動過程(六)之內(nèi)嵌Tomcat中StandardHost、StandardContext和StandardWrapper的啟動教程詳解
- Spring Boot啟動過程(五)之Springboot內(nèi)嵌Tomcat對象的start教程詳解
- Spring Boot啟動過程(四)之Spring Boot內(nèi)嵌Tomcat啟動
- spring boot項(xiàng)目打包成war在tomcat運(yùn)行的全步驟
- SpringBoot應(yīng)用War包形式部署到外部Tomcat的方法
- SpringBoot如何取消內(nèi)置Tomcat啟動并改用外接Tomcat
相關(guān)文章
Java實(shí)現(xiàn)世界上最快的排序算法Timsort的示例代碼
Timsort?是一個(gè)混合、穩(wěn)定的排序算法,簡單來說就是歸并排序和二分插入排序算法的混合體,號稱世界上最好的排序算法。本文將詳解Timsort算法是定義與實(shí)現(xiàn),需要的可以參考一下2022-07-07解決Springboot @Autowired 無法注入問題
WebappApplication 一定要在包的最外層,否則Spring無法對所有的類進(jìn)行托管,會造成@Autowired 無法注入。接下來給大家介紹解決Springboot @Autowired 無法注入問題,感興趣的朋友一起看看吧2018-08-08Java實(shí)現(xiàn)一鍵生成表controller,service,mapper文件
這篇文章主要為大家詳細(xì)介紹了如何利用Java語言實(shí)現(xiàn)一鍵生成表controller,service,mapper文件,文中的示例代碼講解詳細(xì),需要的可以收藏一下2023-05-05基于Springboot執(zhí)行多個(gè)定時(shí)任務(wù)并動態(tài)獲取定時(shí)任務(wù)信息
這篇文章主要為大家詳細(xì)介紹了基于Springboot執(zhí)行多個(gè)定時(shí)任務(wù)并動態(tài)獲取定時(shí)任務(wù)信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04SpringBoot @CompentScan excludeFilters配置無效的解決方案
這篇文章主要介紹了SpringBoot @CompentScan excludeFilters配置無效的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11Java驗(yàn)證時(shí)間格式是否正確方法類項(xiàng)目實(shí)戰(zhàn)
在很多場景中我們需要驗(yàn)證時(shí)間日期的是否屬于正確的格式,驗(yàn)證時(shí)間是否符合常規(guī)的,本文就來介紹一下幾種方式,感興趣的可以了解一下2022-04-04