查了一下网上的资料,需要自己重写一下SqlSessionFactoryBean中的buildSqlSessionFactory方法,并替换原有的SqlSessionFactoryBean
import java.io.IOException; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.core.NestedIOException; public class BeanFactory extends SqlSessionFactoryBean { @Override protected SqlSessionFactory buildSqlSessionFactory() throws IOException { try{ return super.buildSqlSessionFactory(); }catch(NestedIOException e){ e.printStackTrace(); throw new NestedIOException("Failed to parse mapping resource:",e.getCause()); } } }
<bean id="sqlSessionFactory" class="com.izhenglan.merchant.test.bean.BeanFactory">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:config/mybatis-config.xml"/>
<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
</bean>