先说下缘由吧,由于年后跳槽换了家公司,构建项目工具也有maven改成gradle了,所以在搭建框架进行开发打包过程中难免会遇到一些意想不到的问题。
本文简述下打包扫描加载配置文件的异同吧。
maven打包加载配置文件的配置是在pom文件中配置:
1 <resources> 2 <resource> 3 <directory>src/main/resources</directory> 4 <filtering>false</filtering> 5 <includes> 6 <include>**/*.*</include> 7 </includes> 8 </resource> 9 10 <resource> 11 <directory>src/main/resources</directory> 12 <filtering>true</filtering> 13 <excludes> 14 <exclude>**/*.woff</exclude> 15 <exclude>**/*.ttf</exclude> 16 <exclude>**/*.svg</exclude> 17 <exclude>**/*.eot</exclude> 18 </excludes> 19 </resource> 20 21 <resource> 22 <directory>src/main/java</directory> 23 <includes> 24 <include>**/*.properties</include> 25 <include>**/*.xml</include> 26 <include>**/*.yml</include> 27 <include>**/*.html</include> 28 </includes> 29 <filtering>false</filtering> 30 </resource> 31 </resources>
gradle打包加载配置文件的配置是在build.gradle文件中配置:
1 sourceSets { 2 main { 3 java { 4 srcDirs = ['src/main/java','../manager/src/main/java','src/main/webapp'] 5 } 6 resources { 7 srcDirs = ['src/main/resources', '../manager/src/main/resources', 'src/main/webapp'] 8 } 9 } 10 } 11 jar { 12 manifest { 13 attributes 'Main-Class': 'main-class' 14 } 15 }
遇到该问题,也是因为需要将前端页面文件一起加载进行打war包,由于之前没有设置'src/main/webapp',所以导致访问时报404错误,真是粗心大意!!!