mapper3.3.0+spring3报错

chugf 发布于 2015/11/17 17:16
阅读 4K+
收藏 0
Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseSelectProvider.dynamicSQL).  Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
at com.sun.proxy.$Proxy13.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy34.select(Unknown Source)
at com.taoji.fund.service.impl.BaseServiceImpl.select(BaseServiceImpl.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy37.select(Unknown Source)
加载中
0
chugf
chugf
@Liuzh_533 ,我从老的mapper2.3升级到3.3后报这个错误,是哪里配置问题吗?
0
Liuzh_533
Liuzh_533
没有按照文档进行配置。
0
Liuzh_533
Liuzh_533
看看升级日志。
0
chugf
chugf

@Liuzh_533 ,按照你的升级说明配置,OK了!

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">改成了

<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">

这2个类太像了,原来没看仔细,谢谢!

l
lengmianshi
我的问题原来也是这个原因,多谢了
0
chugf
chugf

@Liuzh_533 ,你的"tk.mybatis.spring.mapper.MapperScannerConfigurer"类有问题

maven打包出来运行报错:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
        at com.taoji.fund.sync.main.Application.init(Application.java:24)
        at com.taoji.fund.sync.main.Main.main(Main.java:28)

0
chugf
chugf
不好意思,问题找到了。是java的启动参数问题,-Xss128K改为-Xss1M
0
IT小小生
IT小小生

我要从3.0.0升级到3.3.4,原来spring配置文件中有这么一段:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="multipleDataSource" />
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
reasonable=true
</value>
</property>
</bean>
<bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=com.github.abel533.mapper.Mapper
notEmpty=true
</value>
</property>
</bean>
</array>
</property>

</bean>

请问,现在<bean class="com.github.abel533.mapperhelper.MapperInterceptor">这一段要怎么配置呢?

0
Smart_2
Smart_2

mapper3.3.4  使用 tk.mybatis.spring.mapper.MapperScannerConfigurer扫描, mapper始终

不能被注入进来 

@Liuzh_533

Liuzh_533
Liuzh_533
把你配置发出来看看。
0
Smart_2
Smart_2

applicationContext.xml 


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
	http://www.springframework.org/schema/aop 
	http://www.springframework.org/schema/aop/spring-aop-3.1.xsd			
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-3.1.xsd			
	http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd			
	http://www.springframework.org/schema/cache
	http://www.springframework.org/schema/cache/spring-cache-3.1.xsd			 
	"
	default-autowire="byName" default-lazy-init="true">
	
	<!-- 使用 spring 读取数据库配置信息.properties -->
  	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath*:jdbc/jdbc.properties</value>
			</list>
		</property>
	</bean>
	
	<!-- 数据源  spring dbcp 连接池   -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName">
			<value>${jdbc.driverClassName}</value>
		</property>
		<property name="url">
			<value>${jdbc.url}</value>
		</property>
		<property name="username">
			<value>${jdbc.username}</value>
		</property>
		<property name="password">
			<value>${jdbc.password}</value>
		</property>
	</bean>
	
	<!-- 配置JDBC模板 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

	<!-- 配置事务  -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
   	<!-- Spring-MyBatis 配置   1.数据源引入 2.mybatis配置文件  -->  
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
       	<property name="dataSource" ref="dataSource" />     
  		<property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />
    </bean>  
    
    <!-- 定义Mapper接口扫描-->
   	<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"> 
       		<property name="basePackage" value="com.metter.**.mapper"/>
 	</bean>  
    	
    	
</beans>



mybatis-config.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>  
	
	<!--配置属性的顺序 : properties > settings > typeAliases > typeHandlers > objectFactory >
						objectWrapperFactory > plugins > environments > mappers -->

 	<settings>
         <setting name="cacheEnabled" value="false"/>
         <setting name="useGeneratedKeys" value="true"/>
         <setting name="defaultExecutorType" value="REUSE"/> 
         <setting name="lazyLoadingEnabled" value="false"/>
    </settings>
    
    <typeAliases>
        <typeAlias type="com.metter.common.loginuser.model.LoginUser" alias="LoginUser"/>
    </typeAliases>
    
 	<mappers>
 		<mapper resource="com/metter/common/loginuser/mapper/LoginUserMapper.xml"/>
 	</mappers>
	

</configuration>



目录结构:


包:


Liuzh_533
Liuzh_533
看下面回复,必须配置mappers
0
Liuzh_533
Liuzh_533
<!-- 定义Mapper接口扫描-->
<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"> 
    <property name="basePackage" value="com.metter.**.mapper"/>
</bean>

这个配置不完整,必须配置mappers,你看看文档。




y
yuxuan4508
回复 @giswoduxing : 请问还有配置文件吗?我也遇到这个问题解决不了。。。
g
giswoduxing
回复 @Smart_2 : axiao206102@qq.com,谢谢啊
Smart_2
Smart_2
@giswoduxing 通了。你邮箱 我发给你配置文件
g
giswoduxing
回复 @Smart_2 : 请问你的工程通了吗?我也遇到这个问题了。。。
Liuzh_533
Liuzh_533
回复 @Smart_2 :我说的 通用mapper的mappers属性。
下一页
返回顶部
顶部