创建一个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>
完成下图操作保存即可
配置tomcat启动项
配置视图解析器
创建一个springboot主程序
@springbootapplicationpublic 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的详细内容。