yuanhao_cui
2021-07-25 11:07
采纳率: 25%
浏览 56
已结题

springboot项目打成war包部署到外部tomcat上,排除依赖出现问题

pom文件build模块:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <!-- 没有web.xml 配置的话, 配置为false-->
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <packagingExcludes>
<!--                        排除依赖包-->
                        WEB-INF/lib/*.jar
                    </packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

<!--依赖分离-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!--<outputDirectory>target/lib</outputDirectory>-->
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

如果带着依赖打包,接口可以正常访问

但把依赖包分离出来就无法访问接口, 但是服务能启动

注释内容:

                    <packagingExcludes>
<!--                        排除依赖包-->
                        WEB-INF/lib/*.jar
                    </packagingExcludes>

img

项目是启动成功的
但是无法访问接口
对比了一下有依赖的启动日志
发现去除依赖后少了以下两行日志,怀疑是'dispatcherServlet'没有映射接口路径导致, 有遇到过的嘛

img

  • 收藏

1条回答 默认 最新

  • a1767028198 2021-07-25 11:09
    已采纳

    那是因为你访问了controller,才会初始化dispatchServlet,十有八九是你访问接口url错了

    打赏 评论

相关推荐 更多相似问题