|
maven,spring,mybatis集成的时候单元测试junit测试没问题,但mvn jetty:run 就报错误
错误:
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yd.bpm.rules.dao.GRoleDao.getParticipantList
- at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196) ~[mybatis-3.3.1.jar:3.3.1]
- at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44) ~[mybatis-3.3.1.jar:3.3.1]
- at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.3.1.jar:3.3.1]
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.3.1.jar:3.3.1]
未绑定mapper.xml 正常理解是 mapp.xml 没对应上 dao.java 的方法导致的,但是检查很多遍都能够对应上
applicationContext.xml
- <!-- MyBatis配置 -->
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <!-- 自动扫描目录, 省掉Configuration.xml里的手工配置 -->
- <property name="typeAliasesPackage" value="com.yd.bpm.common.model" />
- <!-- 显式指定Mapper文件位置 -->
- <property name="mapperLocations" value="classpath*:com/yd/bpm/**/*Mapper.xml" />
- </bean>
- <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口-->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.yd.bpm" />
- <property name="annotationClass" value="com.yd.bpm.utils.spring.MyBatisRepository"/>
- </bean>
dao:
- @MyBatisRepository("gRoleDao")
- public interface GRoleDao extends BaseDao<ActorPOJO> {
- /**
- * G_Role 角色查找
- */
- public List<ActorPOJO> getParticipantList(@Param(value="roleIds") String roleIds);
- }
mapper.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <!-- namespace必须指向Dao接口 -->
- <mapper namespace="com.yd.bpm.rules.dao.GRoleDao">
- <select id="getParticipantList" resultType="ActorPOJO" parameterType="String">
- select
- t2.emp_id as id,
- t2.emp_name as name,
- 'person' as typeCode,
- '1' as sortNo
- from bpm_base_position t1
- inner join bpm_base_employee t2 on t2.emp_id = t1.emp_id
- where t1.main_flag = 'y'
- and t1.role_id in (#{roleIds})
- </select>
- </mapper>
反复查看后发现taget 目录下 class 文件中有时没有 mapper.xml ,这时就确认是maven没有 src/main/java下的xml文件拷贝到 target目录下了
在网上搜了下pom.xml的配置方式
加上这个就可以了,如果是其它文件 properties 等 也用这种方式应该也可以解决
来自为知笔记(Wiz) |
|
|