赞
踩
异常:
Caused by: java.io.FileNotFoundException: class path resource [spring-mvc.xml] cannot be opened because it does not exist java.io.FileNotFoundException: class path resource [spring-mvc.xml] cannot be opened because it does not exist
关于在maven项目中出现的如上的bug,springmvc配置文件找不到的情况,但是在target中又是有的 :
且web.xml 文件中的classpath有没有写错的情况:
原因:
maven默认扫描src/main/java中的文件而不理会src/main/resources中的xml文件,所以后来添加了resource节点,这样就将src/main/resources中的xml文件改变maven默认的扫描策略,防止造成src/main/resources下的配置文件打包丢失,具体的代码如下:
在pom.xml文件中加入:
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>
可解决:
参考博客:https://blog.csdn.net/weixin_42696130/article/details/81074317
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。