在用jenkins编译项目,然后发布到tomcat的过程中可能会出现类似这样的错误
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PMInvestEventDetailMapper' defined in file [/home/rdd/workdir/web/tomcat8_2/webapps/ROOT/WEB-INF/classes/com/cv/peseer/dao/PMInvestEventDetailMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/cv/peseer/mapping/*.xml]: class path resource [com/cv/peseer/mapping/] cannot be resolved to URL because it does not exist
意思是找不到相应的mapping文件,这个在本地的eclipse里面是基本不会出现的。原因就在于,使用jenkins编译的时候没有把相应的 xml 打包到war包里。解决的办法就是在项目的pom.xml文件里的build标签下添加如下代码。
<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>
这个就是把java和source目录下的配置文件拷贝到war包的classes目录下。
网友评论