开发者社区> 问答> 正文

请教spring 3+mybatis整合出错问题:Invalid bound s?400报错

请教spring 3+mybatis整合出错问题:Invalid bound statement (not found):? 400 报错

spring 3+mybatis3+spring security整合,我的包和层次结构如下:采用的是按照模块分层,

每层有dao,sevrice,web三个目录,所有的实体类放在model文件夹中

security包中,有dao,service,web三个目录,其中

 SecurityDao.java

@MyBatisDao
public interface SecurityDao extends BaseMapper<Security> {

   // 获得群组usergroups对应的权限
    public List<Security> getGroupResources();

}

SecurityService.java接口

public interface SecurityService extends BaseService<Security>

{

 public List<Security> getGroupResources();

}

SecurityServiceImpl .java

@Service(value = "securityService")
public class SecurityServiceImpl implements SecurityService {
    @Autowired
    private SecurityDao securityDao;

    // 获得群组usergroups对应的权限


    public List<Security> getGroupResources() {
        return securityDao.getGroupResources();
    }
}

MyBatisDao.java

/**
 * 标识MyBatis的DAO,方便{@link org.mybatis.spring.mapper.MapperScannerConfigurer}的扫描。 
 * 
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Component
public @interface MyBatisDao {

/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any
*/
String value() default "";


}

然后系统有一个model的包,存放各模块的实体类这里有security.java,get/set就省略

了,

然后在maven的resource下建立文件src\resource\mappings\modules\security\SecurityDao.xml


<mapper namespace="com.liao.modules.core.security.dao.SecurityDao">

<resultMap id="getUserInfoMap" type="Security">
<result property="userid" column="userid"/>
<result property="username" column="username"/>
<result property="password" column="password"/>
<result property="enabled" column="enabled"/>

</resultMap>

  <select id="getGroupResources" resultType="Security">
         select g.role_name roleName,a.url resourceValue from usergroups g
         join groupauthority_mapping  ga on g.groupid=ga.groupid
         join authority a on ga.authorityid=a.authorityid
</select>

.....

spring-mvc.xml:

<!-- 自动扫描bean,把作了注解的类转换为bean -->
<context:component-scan base-package="com.liao" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

其他mvc配置省略

spring-context-application.xml:

  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动匹配Mapper映射文件 -->
<property name="mapperLocations" value="classpath:mappings/**/*.xml"/>
<property name="typeAliasesPackage" value="com.liao.model"/>

<property name="configLocation" value="classpath:/mybatis-config.xml"></property>

</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.liao" />
  <property name="annotationClass" value="com.itownet.isms.core.annotation.MyBatisDao"/>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
<!-- 事务配置 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

mybatis-config.xml:

<configuration>


<!-- 全局参数 -->
<settings>
<!-- 使全局的映射器启用或禁用缓存。 -->
<setting name="cacheEnabled" value="true"/>

<!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 -->
<setting name="lazyLoadingEnabled" value="true"/>

<!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 -->
<setting name="aggressiveLazyLoading" value="true"/>

<!-- 是否允许单条sql 返回多个数据集  (取决于驱动的兼容性) default:true -->
<setting name="multipleResultSetsEnabled" value="true"/>

<!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true -->
<setting name="useColumnLabel" value="true"/>

<!-- 允许JDBC 生成主键。需要驱动器支持。如果设为了true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。  default:false  -->
<setting name="useGeneratedKeys" value="false"/>

<!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE:不隐射 PARTIAL:部分  FULL:全部  -->  
<setting name="autoMappingBehavior" value="PARTIAL"/>

<!-- 这是默认的执行类型  (SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句;BATCH: 执行器可以重复执行语句和批量更新)  -->
<setting name="defaultExecutorType" value="SIMPLE"/>

<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>

<!-- 设置本地缓存范围 session:就会有数据的共享  statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
        <setting name="localCacheScope" value="SESSION"/>

        <!-- 设置但JDBC类型为空时,某些驱动程序 要指定值,default:OTHER,插入空值时不需要指定类型 -->
        <setting name="jdbcTypeForNull" value="NULL"/>

</settings>


在spring secrutiy中,调用

public class DefinitionSourceFactoryBean implements FilterInvocationSecurityMetadataSource {
    @Autowired
    private SecurityService securityService;
public void findResources() {

  List<Security> resourcesgroup = securityService.getGroupResources();

 这个时候在运行securityService.getGroupResources();,说:

mybatis,Invalid bound statement (not found): com.liao.core.security.dao.SecurityDao.getGroupResources


 编译后,已经检查过,maoper.xml在web-inf\classes目录下了,为什么呢?


展开
收起
爱吃鱼的程序员 2020-05-30 23:56:27 599 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    SecurityDao的包名与mapper中的com.liao.modules.core.security.dao.SecurityDao不一样######up######up,继续顶,哪位兄弟讲解下######up,继续顶,哪位兄弟讲解下!######你看下SecurityDao.xml 中的select有没有写错,resultType 会是 Security吗?######

    引用来自“小小志”的评论

    SecurityDao的包名与mapper中的com.liao.modules.core.security.dao.SecurityDao不一样
    yes,这里错了######还是看不出哪里错
    2020-05-30 23:56:28
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Hoxton 新版本介绍 & 未来展望 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载

相关实验场景

更多