Fork me on GitHub

SpringBoot添加WEB模块

添加Web模块

打开Structure,在Modules中添加Web模块,并配置好web.xml喝web根路径

 

Package到jar中

上面的添加好后直接运行在浏览器中可以访问,package打包成jar包后发现访问不了,原因是没把webapp模块打包到jar中。

在pom文件的build节点下添加resource配置,目的是将webapps下的目录打包到jar文件的META-INF\resources目录下

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <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>

posted @ 2020-03-14 21:41  秋夜雨巷  阅读(3859)  评论(0编辑  收藏  举报