Home > Java > javaTutorial > How to use external tomcat to configure springboot in idea

How to use external tomcat to configure springboot in idea

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-12 11:10:13
forward
876 people have browsed it
  • Create a maven project

  • Import springboot dependencies, pay attention to the comments below

<?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>
Copy after login

How to use external tomcat to configure springboot in idea

How to use external tomcat to configure springboot in idea

Complete the operation below and save it

How to use external tomcat to configure springboot in idea

Configure tomcat startup items

How to use external tomcat to configure springboot in idea

How to use external tomcat to configure springboot in idea

How to use external tomcat to configure springboot in idea

How to use external tomcat to configure springboot in idea

Configure view resolver

How to use external tomcat to configure springboot in idea

Create a springboot main program

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

You must write a subclass of SpringBootServletInitializer and call the fixed writing method in the configure method

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

Then start tomcat, the console output Spring started successfully

How to use external tomcat to configure springboot in idea

The above is the detailed content of How to use external tomcat to configure springboot in idea. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template