1.我们创建一个spring-boot-create-tomcat项目
2.可以看到pom文件里面会多一个spring-boot-starter-tomcat的包
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.qjc</groupId>
<artifactId>spring-boot-cretate-tomcat</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>spring-boot-cretate-tomcat</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.我们可以用tomcat 去加载一下,然后启动
如图:
一月 24, 2019 1:47:50 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:spring-boot-cretate-tomcat' did not find a matching property.
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/9.0.2
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: Nov 25 2017 21:08:02 UTC
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 9.0.2.0
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Windows 10
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 10.0
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture: amd64
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home: D:\Java\jdk1.8.0_181\jre
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version: 1.8.0_181-b13
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor: Oracle Corporation
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE: D:\aihaimiTomcat\springboot
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME: D:\aihaimiTomcat\springboot
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\aihaimiTomcat\springboot
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\aihaimiTomcat\springboot
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\aihaimiTomcat\springboot\wtpwebapps
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\aihaimiTomcat\springboot\endorsed
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=GBK
一月 24, 2019 1:47:50 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\Java\jdk1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:/Java/jre1.8.0_181/bin/server;D:/Java/jre1.8.0_181/bin;D:/Java/jre1.8.0_181/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\OpenVPN\bin;d:\Program Files\Git\cmd;D:\Java\jdk1.8.0_181\bin;D:\Maven\apache-maven-3.5.0\bin;D:\Program Files\TortoiseSVN\bin;C:\WINDOWS\System32\OpenSSH\;d:\Program Files\Microsoft VS Code\bin;D:\Program Files\nodejs\;C:\Users\joe\AppData\Local\Microsoft\WindowsApps;;d:\Program Files\Microsoft VS Code\bin;d:\Fiddler;C:\Users\joe\AppData\Local\Microsoft\WindowsApps;C:\Users\joe\AppData\Roaming\npm;D:\J2EEBoot\eclipse;;.]
一月 24, 2019 1:47:50 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8080"]
一月 24, 2019 1:47:50 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
一月 24, 2019 1:47:50 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-nio-8009"]
一月 24, 2019 1:47:50 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
一月 24, 2019 1:47:50 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 775 ms
一月 24, 2019 1:47:50 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Catalina]
一月 24, 2019 1:47:50 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/9.0.2
一月 24, 2019 1:47:52 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
一月 24, 2019 1:47:52 下午 org.apache.catalina.core.ApplicationContext log
信息: 2 Spring WebApplicationInitializers detected on classpath
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-01-24 13:47:53.339 INFO 16392 --- [ main] com.qjc.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on DESKTOP-580CUKI with PID 16392 (D:\aihaimiTomcat\springboot\wtpwebapps\spring-boot-cretate-tomcat\WEB-INF\classes started by joe in D:\J2EEBoot\eclipse)
2019-01-24 13:47:53.345 INFO 16392 --- [ main] com.qjc.ServletInitializer : No active profile set, falling back to default profiles: default
2019-01-24 13:47:54.355 INFO 16392 --- [ main] .c.c.C.[.[.[/spring-boot-cretate-tomcat] : Initializing Spring embedded WebApplicationContext
2019-01-24 13:47:54.355 INFO 16392 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 933 ms
2019-01-24 13:47:54.890 INFO 16392 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-24 13:47:55.132 INFO 16392 --- [ main] com.qjc.ServletInitializer : Started ServletInitializer in 2.381 seconds (JVM running for 5.13)
2019-01-24 13:47:55.155 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [D:\aihaimiTomcat\springboot\webapps\docs]
2019-01-24 13:47:55.169 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [D:\aihaimiTomcat\springboot\webapps\docs] has finished in [13] ms
2019-01-24 13:47:55.169 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [D:\aihaimiTomcat\springboot\webapps\examples]
2019-01-24 13:47:55.378 INFO 16392 --- [ main] o.a.c.c.C.[.[localhost].[/examples] : ContextListener: contextInitialized()
2019-01-24 13:47:55.378 INFO 16392 --- [ main] o.a.c.c.C.[.[localhost].[/examples] : SessionListener: contextInitialized()
2019-01-24 13:47:55.383 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [D:\aihaimiTomcat\springboot\webapps\examples] has finished in [214] ms
2019-01-24 13:47:55.384 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [D:\aihaimiTomcat\springboot\webapps\host-manager]
2019-01-24 13:47:55.406 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [D:\aihaimiTomcat\springboot\webapps\host-manager] has finished in [22] ms
2019-01-24 13:47:55.406 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [D:\aihaimiTomcat\springboot\webapps\manager]
2019-01-24 13:47:55.424 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [D:\aihaimiTomcat\springboot\webapps\manager] has finished in [18] ms
2019-01-24 13:47:55.424 INFO 16392 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [D:\aihaimiTomcat\springboot\webapps\ROOT]
2019-01-24 13:47:55.438 INFO 16392 --- [ main] org.apache..startup.HostConfig : Deployment of web application directory [D:\aihaimiTomcat\springboot\webapps\ROOT] has finished in [14] ms
2019-01-24 13:47:55.455 INFO 16392 --- [ main] org.apache.coyote.ajp.AjpNioProtocol : Starting ProtocolHandler ["ajp-nio-8009"]
2019-01-24 13:47:55.459 INFO 16392 --- [ main] org.apache.catalina.startup.Catalina : Server startup in 4497 ms
可以看到tomcat启动成功。
4.项目源码地址
https://github.com/joecheng521/springboot/tree/master/spring-boot-cretate-tomcat