温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

idea怎么使用外置tomcat配置springboot

发布时间:2022-04-02 16:02:02 来源:亿速云 阅读:362 作者:iii 栏目:移动开发

本篇内容介绍了“idea怎么使用外置tomcat配置springboot”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

  •  创建一个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

“idea怎么使用外置tomcat配置springboot”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI