idea使用外置tomcat配置springboot详细步骤

作者:丶楠忆 时间:2023-11-20 03:56:49 

  •  创建一个maven项目

  • 导入springboot依赖,注意底 * 释部分


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

<groupId>com.znsd.springboot</groupId>
   <artifactId>springboot-jsp</artifactId>
   <version>1.0-SNAPSHOT</version>

<!-- 一定要声明war包 -->
   <packaging>war</packaging>
   <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.3.12.RELEASE</version>
       <relativePath/> <!-- lookup parent from repository -->
   </parent>

<dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>

<!-- 去除springboot默认tomcat依赖,让其在生成war包时无效, -->
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
           <!--在编译和测试有效,生成war包时无效-->
           <scope>provided</scope>
       </dependency>

<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
           <exclusions>
               <exclusion>
                   <groupId>org.junit.vintage</groupId>
                   <artifactId>junit-vintage-engine</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
   </dependencies>

<build>
       <plugins>
           <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
           </plugin>
       </plugins>
   </build>
</project>

idea使用外置tomcat配置springboot详细步骤

idea使用外置tomcat配置springboot详细步骤

完成下图操作保存即可

idea使用外置tomcat配置springboot详细步骤

配置tomcat启动项

idea使用外置tomcat配置springboot详细步骤

idea使用外置tomcat配置springboot详细步骤

idea使用外置tomcat配置springboot详细步骤

idea使用外置tomcat配置springboot详细步骤

配置视图解析器

idea使用外置tomcat配置springboot详细步骤

创建一个springboot主程序


@SpringBootApplication
public class SpringBootMain {
   public static void main(String[] args) {
       SpringApplication.run(SpringBootMain.class,args);
   }
}

必须编写一个SpringBootServletInitializer的子类,并调用configure方法里面的固定写法


public class ServletInitializer extends SpringBootServletInitializer {
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
       //传入SpringBoot的主程序,
       return application.sources(SpringBootMain.class);
   }
}

然后启动tomcat,控制台输出了spring就启动成功了

idea使用外置tomcat配置springboot详细步骤

来源:https://www.cnblogs.com/nanyiaka/p/14959805.html

标签:idea,springboot,tomcat
0
投稿

猜你喜欢

  • android仿微信支付宝的支付密码输入框示例

    2023-09-27 22:11:47
  • 教你3分钟了解Android 简易时间轴的实现方法

    2023-04-02 20:56:19
  • 详解Idea 2019.2 安装lombok插件失效问题解决

    2023-05-01 09:22:59
  • Android通过AIDL在两个APP之间Service通信

    2022-04-15 23:58:27
  • .net的序列化与反序列化实例

    2022-12-29 00:50:50
  • 详解Java ES多节点任务的高效分发与收集实现

    2021-08-03 13:59:02
  • C#创建安全的栈(Stack)存储结构

    2021-11-21 08:01:33
  • C# Email发送邮件 对方打开邮件可获得提醒

    2022-01-07 17:59:14
  • java多线程之铁路售票系统

    2022-01-31 12:25:14
  • java并发包JUC同步器框架AQS框架原文翻译

    2022-08-22 22:17:23
  • Android中SurfaceView和view画出触摸轨迹

    2023-12-13 22:37:28
  • Java 实战项目之小说在线阅读系统的实现流程

    2022-01-31 07:41:49
  • C#如何通过probing指定dll寻找文件夹详解

    2023-07-22 12:59:37
  • 接口签名怎么用Java实现

    2023-02-18 03:22:10
  • Android自定义软键盘的步骤记录

    2023-04-08 07:05:50
  • Java调用groovy实现原理代码实例

    2023-05-16 16:41:51
  • SpringBoot整合XxlJob分布式任务调度平台

    2022-07-09 09:47:37
  • java使用dom4j操作xml示例代码

    2022-03-21 18:28:38
  • C语言数据结构之二叉树的非递归后序遍历算法

    2021-12-23 07:10:52
  • java内存优化的方法总结

    2022-12-01 22:25:20
  • asp之家 软件编程 m.aspxhome.com