添加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>