springmvc+mybatis 批量扫描别名

maohaomaohaomao 2017-06-09 09:58:10
springmvc+mybatis 可引入批量批量扫描别名文件(确定sqlMapConfig.xml被成功引入了),但是在某xml文件中将全类名换成别名时报错,相关配置及报错信息如下:
1.applicationContext-dao.xml(主要看标红的部分)如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

<!-- 加载db.properties文件中的内容,db.properties文件中key命名要有一定的特殊规则 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 配置数据源 ,dbcp -->

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxActive" value="30" />
<property name="maxIdle" value="5" />
</bean>
<!-- sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文件 -->
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
</bean>
<!-- mapper扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 扫描包路径,如果需要扫描多个包,中间使用半角逗号隔开 -->
<property name="basePackage" value="com.roboo.newsad.mapper.advertiser"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>
2.sqlMapConfig.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<!-- 批量扫描别名 -->
<package name="com.roboo.newsad.po.advertiser"/>
</typeAliases>
</configuration>
3.com.roboo.newsad.mapper.advertiser下的UserAdvertiserImgMapper.xml文件部分代码,将原来的全类名com.roboo.newsad.po.advertiser.UserAdvertiserImg换成userAdvertiserImg:
<!-- <update id="updateByPrimaryKey" parameterType="com.roboo.newsad.po.advertiser.UserAdvertiserImg" > -->
<update id="updateByPrimaryKey" parameterType="userAdvertiserImg" >

update user_advertiser_img
set uaid = #{uaid,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
alikey = #{alikey,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
dateCreation = #{datecreation,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
做了3中的类名替换步骤后报错如下:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userAdvertiserImgMapper'
defined in file [E:\Work\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
\webapps\newsad.roboo.com\WEB-INF\classes\com\roboo\newsad\mapper\advertiser\UserAdvertiserImgMapper.class]:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
Cause: org.apache.ibatis.builder.BuilderException: Error resolving class.
Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'userAdvertiserImg'.
Cause: java.lang.ClassNotFoundException: Cannot find class: userAdvertiserImg
...全文
267 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧