Error creating bean with name ‘sqlSessionFactory‘ defined in class path resource

报错如下:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [spring-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]’. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.kuang.mapper.UserMapper.selectUser. please check com/kuang/mapper/UserMapper.xml and file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [spring-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]’. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.kuang.mapper.UserMapper.selectUser. please check com/kuang/mapper/UserMapper.xml and file [D:\Program Files\spring-study\Spring-10-Mybatis\target\classes\com\kuang\mapper\UserMapper.xml]

我报这个错,是因为我在spring-dao.xml和mybatis-config.xml都扫描了UserMapper
具体代码如下:

    <mappers>
        <mapper class="com.kuang.mapper.UserMapper"/>
    mappers>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>

        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:com/kuang/mapper/*.xml"/>
    bean>

你可能感兴趣的:(spring,integration)