bbqmdot 2015-06-30 08:34 采纳率: 0%
浏览 1996

请教spring 3+mybatis整合出错问题

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

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

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

SecurityDao.java
@MyBatisDao
public interface SecurityDao extends BaseMapper {

// 获得群组usergroups对应的权限
public List 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目录下了,为什么呢?

  • 写回答

2条回答

  • 丵鹰 2015-06-30 08:44
    关注

    应该是mybatis-config.xml中 mapper这个maoper.xml文件 如

    评论

报告相同问题?

悬赏问题

  • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波