报 java.lang.ExceptionInInitializerError 的常见解决方法

报 java.lang.ExceptionInInitializerError 的常见解决方法

0. 如果你是遇到这个问题?

java.lang.ExceptionInInitializerError
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/xu/dao/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/xu/dao/UserMapper.xml
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.xu.utils.MybatisUtils.<clinit>(MybatisUtils.java:27)
	... 23 more

1. mybatis的配置文件是否有错

不管是放在src/main/java还是src/main/resources下的目录,都是只需要写Java之后的的路径,如:

mapper路径

2. 检查是否放行静态资源

需要在pom问价加入以下代码:

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

3.点击maven的Lifecycle中clean然后检查是否出现pom中配置问题

如果点检clean出现以下问题,

maven报错

请检查pom文件,特别是以下几个标签是否有错:

	<groupId>组ID</groupId>
    <artifactId>项目名</artifactId>
    <packaging>pom</packaging>
posted @ 2020-09-22 20:24  小徐学狂  阅读(10677)  评论(0编辑  收藏  举报