• springboot去除内嵌tomcat和打包在tomcat中运行需要做的步骤


    去除内嵌tomcat和添加jsp依赖

    去除内嵌tomcat

    在springboot启动依赖中去除内嵌tomcat
            <dependency>
    		            <groupId>org.springframework.boot</groupId>
    		            <artifactId>spring-boot-starter-web</artifactId>
    		            <!-- 移除嵌入式tomcat插件 -->
    		            <exclusions>
    		                <exclusion>
    		                    <groupId>org.springframework.boot</groupId>
    		                    <artifactId>spring-boot-starter-tomcat</artifactId>
    		                </exclusion>
    		            </exclusions>
    		        </dependency>

    添加servlet和jsp依赖

            <dependency>
    		            <groupId>javax.servlet</groupId>
    		            <artifactId>javax.servlet-api</artifactId>
    		        </dependency>
    		
    		        <dependency>
    		            <groupId>javax.servlet</groupId>
    		            <artifactId>jstl</artifactId>
    		        </dependency>
    		        <dependency>
    		            <groupId>org.apache.tomcat.embed</groupId>
    		            <artifactId>tomcat-embed-jasper</artifactId>
    		        </dependency>

    打包项目在tomcat运行需要的步骤

    一定要设置成war包(好吧这是废话)

    不需要jsp的pom配置

    <build>
    			<!-- ⭐️打包后的包名 -->
    		        <finalName>demo</finalName>
    		        <plugins>
    		            <plugin>
    		                <groupId>org.springframework.boot</groupId>
    		                <artifactId>spring-boot-maven-plugin</artifactId>
    		                <configuration>
    		                    <!-- ⭐️设定启动类 -->
    		                    <mainClass>com.example.DemoApplication</mainClass>
    		                </configuration>
    		                <executions>
    		                    <execution>
    		                        <goals>
    		                            <goal>repackage</goal>
    		                        </goals>
    		                    </execution>
    		                </executions>
    		            </plugin>
    		        </plugins>
    		    </build>

    需要jsp的pom配置

    <build>
    		        <finalName>demo</finalName>
    		        <plugins>
    		            <plugin>
    		                <groupId>org.springframework.boot</groupId>
    		                <artifactId>spring-boot-maven-plugin</artifactId>
    		                <version>1.4.2.RELEASE</version>
    		                <configuration>
    		                    <!-- ⭐️设定启动类 -->
    		                    <mainClass>com.example.DemoApplication</mainClass>
    		                </configuration>
    		                <executions>
    		                    <execution>
    		                        <goals>
    		                            <goal>repackage</goal>
    		                        </goals>
    		                    </execution>
    		                </executions>
    		            </plugin>
    		        </plugins>
    		        <resources>
    		            <resource>
    		                <!-- ⭐️JSP包打包到资源里 -->
    		                <directory>src/main/webapp</directory>
    		                <targetPath>META-INF/resources</targetPath>
    		                <includes>
    		                    <include>**/**</include>
    		                </includes>
    		            </resource>
    		            <resource>
    		                <!-- ⭐️其他资打包到资源里 -->
    		                <directory>src/main/resources</directory>
    		                <includes>
    		                    <include>**/**</include>
    		                </includes>
    		                <filtering>false</filtering>
    		            </resource>
    		        </resources>
    		    </build>

    为了tomcat运行项目后启动springboot需要新建一个类继承SpringBootServletInitializer类

    public class TomCatApplication extends SpringBootServletInitializer {
    			
    			
    			    @Override
    			    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    			        return builder.sources(DemoApplication.class);
    			    }
    			
    			}

    其实可以直接让Springboot启动类继承重写也是可以的

    现在打包后放到tomcat容器运行即可,端口看tomcat的,访问名看tomcat容器显示的文件夹名

  • 相关阅读:
    Luogu P1020 导弹拦截
    MySQL事务隔离级别和实现原理
    classloader加载class文件的原理和机制
    Spring Bean的生命周期只有这四个阶段
    Spring 源码:BeanFactory 简介以及它 和FactoryBean的区别
    开闭原则——面向对象设计原则
    HashSet的实现原理
    装饰器模式(装饰设计模式)详解
    在java中,HashMap 或者HashTable,它们的键值被放满了,会出现什么情况?
    Mybitis 批量插入实践
  • 原文地址:https://www.cnblogs.com/mowen120/p/12300893.html
Copyright © 2020-2023  润新知