最近使用Eclipse做maven web项目,配置maven的profile,部署到tomcat时总是报
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from class path resource [spring-config.xml]; nested exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
//中间信息省略
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
错误信息显示:是spring解析spring-config.xml配置文件时发生编码错误!
但查看了整个项目和配置文件的编码格式全是UTF-8!!!
那么问题来了,到底是那个环节造成了配置文件的编码格式不对?!!!
感觉应该是maven出现了问题,查看了maven中和资源文件处理有关的maven-resources-plugin的作用,是部署时,将项目的资源文件复制到对应的文件夹中。
于是考虑配置pom中maven-resources-plugin插件的编码方式为UTF-8,如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
因为修改了pom配置,所以手动地更新一下maven项目,是maven的更新项目!可以选中项目名,然后alt
+F5
快捷键更新项目,然后重新部署,显示部署正常,问题搞定!