springboot部署到tomcat

深碍√TFBOYSˉ_ 2022-04-15 02:23 415阅读 0赞

1.创建maven工程,添加依赖,pom文件类容如下:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.szcatic</groupId>
  5. <artifactId>springboot</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <packaging>war</packaging>
  8. <name>springboot</name>
  9. <url>http://maven.apache.org</url>
  10. <parent>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-parent</artifactId>
  13. <version>2.1.0.RELEASE</version>
  14. </parent>
  15. <dependencies>
  16. <dependency>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-web</artifactId>
  19. </dependency>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-test</artifactId>
  23. <scope>test</scope>
  24. </dependency>
  25. <!-- junit5运行所需jar包 -->
  26. <dependency>
  27. <groupId>org.junit.jupiter</groupId>
  28. <artifactId>junit-jupiter-engine</artifactId>
  29. <scope>test</scope>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.junit.platform</groupId>
  33. <artifactId>junit-platform-runner</artifactId>
  34. <scope>test</scope>
  35. </dependency>
  36. </dependencies>
  37. <properties>
  38. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  39. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  40. <java.version>1.8</java.version>
  41. <!-- 指定springboot入口类 -->
  42. <start-class>com.szcatic.Application</start-class>
  43. </properties>
  44. <build>
  45. <plugins>
  46. <plugin>
  47. <groupId>org.springframework.boot</groupId>
  48. <artifactId>spring-boot-maven-plugin</artifactId>
  49. <configuration>
  50. <source>1.8</source>
  51. <target>1.8</target>
  52. </configuration>
  53. </plugin>
  54. </plugins>
  55. </build>
  56. </project>

此处注意com.szcatic.Application

2.创建应用程序入口类Application.java

  1. package com.szcatic;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.boot.builder.SpringApplicationBuilder;
  5. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8. @SpringBootApplication
  9. @RestController
  10. public class Application extends SpringBootServletInitializer {
  11. @Override
  12. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  13. return application.sources(Application.class);
  14. }
  15. public static void main(String[] args) {
  16. SpringApplication.run(Application.class, args);
  17. }
  18. @RequestMapping("/hello")
  19. public String getHello() {
  20. return "Hello World";
  21. }
  22. }

3.添加项目到tomcat服务

20181120141309361.png

4.启动tomcat服务,控制台类容如下

  1. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  2. 信息: Server version: Apache Tomcat/9.0.8
  3. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  4. 信息: Server built: Apr 27 2018 19:32:00 UTC
  5. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  6. 信息: Server number: 9.0.8.0
  7. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  8. 信息: OS Name: Windows 10
  9. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  10. 信息: OS Version: 10.0
  11. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  12. 信息: Architecture: amd64
  13. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  14. 信息: Java Home: E:\JDK\jdk1.8.0_171\jre
  15. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  16. 信息: JVM Version: 1.8.0_171-b11
  17. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  18. 信息: JVM Vendor: Oracle Corporation
  19. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  20. 信息: CATALINA_BASE: E:\Tomcat\apache-tomcat-9.0.8
  21. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  22. 信息: CATALINA_HOME: E:\Tomcat\apache-tomcat-9.0.8
  23. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  24. 信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:65131
  25. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  26. 信息: Command line argument: -Dcatalina.base=E:\Tomcat\apache-tomcat-9.0.8
  27. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  28. 信息: Command line argument: -Dcatalina.home=E:\Tomcat\apache-tomcat-9.0.8
  29. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  30. 信息: Command line argument: -Dwtp.deploy=F:\workspace4.7
  31. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  32. 信息: Command line argument: -Djava.endorsed.dirs=E:\Tomcat\apache-tomcat-9.0.8\endorsed
  33. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.startup.VersionLoggerListener log
  34. 信息: Command line argument: -Dfile.encoding=UTF-8
  35. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
  36. 信息: Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
  37. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
  38. 信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
  39. 十一月 20, 2018 2:13:22 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
  40. 信息: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
  41. 十一月 20, 2018 2:13:23 下午 org.apache.catalina.core.AprLifecycleListener initializeSSL
  42. 信息: OpenSSL successfully initialized [OpenSSL 1.0.2m 2 Nov 2017]
  43. 十一月 20, 2018 2:13:23 下午 org.apache.coyote.AbstractProtocol init
  44. 信息: Initializing ProtocolHandler ["http-nio-8080"]
  45. 十一月 20, 2018 2:13:24 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
  46. 信息: Using a shared selector for servlet write/read
  47. 十一月 20, 2018 2:13:24 下午 org.apache.coyote.AbstractProtocol init
  48. 信息: Initializing ProtocolHandler ["ajp-nio-8009"]
  49. 十一月 20, 2018 2:13:24 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
  50. 信息: Using a shared selector for servlet write/read
  51. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.startup.Catalina load
  52. 信息: Initialization processed in 3555 ms
  53. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.core.StandardService startInternal
  54. 信息: Starting service [Catalina]
  55. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.core.StandardEngine startInternal
  56. 信息: Starting Servlet Engine: Apache Tomcat/9.0.8
  57. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.startup.HostConfig deployDescriptor
  58. 信息: Deploying deployment descriptor [E:\Tomcat\apache-tomcat-9.0.8\conf\Catalina\localhost\springboot.xml]
  59. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.startup.HostConfig deployDescriptor
  60. 警告: The path attribute with value [/springboot] in deployment descriptor [E:\Tomcat\apache-tomcat-9.0.8\conf\Catalina\localhost\springboot.xml] has been ignored
  61. 十一月 20, 2018 2:13:24 下午 org.apache.catalina.startup.SetContextPropertiesRule begin
  62. 警告: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:springboot' did not find a matching property.
  63. 十一月 20, 2018 2:13:29 下午 org.apache.jasper.servlet.TldScanner scanJars
  64. 信息: 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.
  65. 十一月 20, 2018 2:13:29 下午 org.apache.catalina.core.ApplicationContext log
  66. 信息: 1 Spring WebApplicationInitializers detected on classpath
  67. . ____ _ __ _ _
  68. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  69. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  70. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  71. ' |____| .__|_| |_|_| |_\__, | / / / /
  72. =========|_|==============|___/=/_/_/_/
  73. :: Spring Boot :: (v2.1.0.RELEASE)
  74. 2018-11-20 14:13:31.235 INFO 9968 --- [ main] com.szcatic.Application : Starting Application on zsx with PID 9968 (F:\workspace4.7\springboot\target\classes started by admin in E:\eclipse)
  75. 2018-11-20 14:13:31.245 INFO 9968 --- [ main] com.szcatic.Application : No active profile set, falling back to default profiles: default
  76. 2018-11-20 14:13:33.411 INFO 9968 --- [ main] o.a.c.c.C.[.[localhost].[/springboot] : Initializing Spring embedded WebApplicationContext
  77. 2018-11-20 14:13:33.411 INFO 9968 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2012 ms
  78. 2018-11-20 14:13:33.991 INFO 9968 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
  79. 2018-11-20 14:13:34.052 INFO 9968 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
  80. 2018-11-20 14:13:34.052 INFO 9968 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
  81. 2018-11-20 14:13:34.052 INFO 9968 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  82. 2018-11-20 14:13:34.052 INFO 9968 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
  83. 2018-11-20 14:13:34.052 INFO 9968 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
  84. 2018-11-20 14:13:34.563 INFO 9968 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
  85. 2018-11-20 14:13:35.010 INFO 9968 --- [ main] com.szcatic.Application : Started Application in 4.9 seconds (JVM running for 15.165)
  86. 2018-11-20 14:13:35.071 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of deployment descriptor [E:\Tomcat\apache-tomcat-9.0.8\conf\Catalina\localhost\springboot.xml] has finished in [10,763] ms
  87. 2018-11-20 14:13:35.120 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application archive [E:\Tomcat\apache-tomcat-9.0.8\webapps\axis2.war]
  88. 2018-11-20 14:13:40.961 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  89. [INFO] Clustering has been disabled
  90. [INFO] Deploying module: addressing-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/addressing-1.7.8.mar
  91. [INFO] Deploying module: jaxws-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/axis2-jaxws-mar-1.7.8.mar
  92. [INFO] Deploying module: metadataExchange-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/mex-1.7.8.mar
  93. [INFO] Deploying module: mtompolicy-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/mtompolicy-1.7.8.mar
  94. [INFO] Deploying module: ping-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/ping-1.7.8.mar
  95. [INFO] Deploying module: script-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/scripting-1.7.8.mar
  96. [INFO] Deploying module: soapmonitor-1.7.8 - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/modules/soapmonitor-1.7.8.mar
  97. [INFO] Deploying Web service: version-1.7.8.aar - file:/E:/Tomcat/apache-tomcat-9.0.8/webapps/axis2/WEB-INF/services/version-1.7.8.aar
  98. [INFO] Deploying pojo: ComplexTypeServices - E:\Tomcat\apache-tomcat-9.0.8\webapps\axis2\WEB-INF\pojo\ComplexTypeServices.class
  99. [INFO] Deploying pojo: SimpleService - E:\Tomcat\apache-tomcat-9.0.8\webapps\axis2\WEB-INF\pojo\SimpleService.class
  100. 2018-11-20 14:13:42.138 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application archive [E:\Tomcat\apache-tomcat-9.0.8\webapps\axis2.war] has finished in [7,018] ms
  101. 2018-11-20 14:13:42.139 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\docs]
  102. 2018-11-20 14:13:43.480 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  103. 2018-11-20 14:13:43.485 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\docs] has finished in [1,346] ms
  104. 2018-11-20 14:13:43.485 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\examples]
  105. 2018-11-20 14:13:45.298 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  106. 2018-11-20 14:13:45.380 INFO 9968 --- [ main] o.a.c.c.C.[.[localhost].[/examples] : ContextListener: contextInitialized()
  107. 2018-11-20 14:13:45.381 INFO 9968 --- [ main] o.a.c.c.C.[.[localhost].[/examples] : SessionListener: contextInitialized()
  108. 2018-11-20 14:13:45.383 INFO 9968 --- [ main] o.a.c.c.C.[.[localhost].[/examples] : ContextListener: attributeAdded('StockTicker', 'async.Stockticker@30e338ff')
  109. 2018-11-20 14:13:45.398 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\examples] has finished in [1,913] ms
  110. 2018-11-20 14:13:45.399 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\host-manager]
  111. 2018-11-20 14:13:46.841 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  112. 2018-11-20 14:13:46.862 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\host-manager] has finished in [1,464] ms
  113. 2018-11-20 14:13:46.863 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\manager]
  114. 2018-11-20 14:13:48.156 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  115. 2018-11-20 14:13:48.163 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\manager] has finished in [1,299] ms
  116. 2018-11-20 14:13:48.163 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deploying web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\ROOT]
  117. 2018-11-20 14:13:49.402 INFO 9968 --- [ main] org.apache.jasper.servlet.TldScanner : 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.
  118. 2018-11-20 14:13:49.407 INFO 9968 --- [ main] org.apache.catalina.startup.HostConfig : Deployment of web application directory [E:\Tomcat\apache-tomcat-9.0.8\webapps\ROOT] has finished in [1,244] ms
  119. 2018-11-20 14:13:49.507 INFO 9968 --- [ main] org.apache.coyote.ajp.AjpNioProtocol : Starting ProtocolHandler ["ajp-nio-8009"]
  120. 2018-11-20 14:13:49.519 INFO 9968 --- [ main] org.apache.catalina.startup.Catalina : Server startup in 25313 ms

5.打开浏览器,输入网址http://localhost:8080/springboot/hello,显示如下,表示部署到tomcat成功

20181120141524731.png

发表评论

表情:
评论列表 (有 0 条评论,415人围观)

还没有评论,来说两句吧...

相关阅读