Java-Spring-Ibatis 配置的典型模式

 

spring-ibatis 配置的典型模式,若没有 default-lazy-init="true" 这个设置,将抛出下面异常

 

 

缺少 default-lazy-init="true" 设置时候的异常
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClientDaoSupport' defined in class path resource [applicationContext-jeaf-amp.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.ibatis.support.SqlMapClientDaoSupport]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
 

 

 

 

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.directwebremoting.org/schema/spring-dwr
    http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" 
  default-lazy-init="true"> <!-- 缺了 default-lazy-init="true" 这个设置,sqlMapClientDaoSupport 定义处会出错  -->

	<!-- 定义受环境影响易变的变量 -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<value>classpath*:/jdbc.properties</value>
			</list>
		</property>
	</bean>
	
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="initialSize" value="1" />
		<property name="maxActive" value="2" />
		<property name="maxIdle" value="1" />
		<property name="maxWait" value="1000" />
		<property name="poolPreparedStatements" value="true" />
		<property name="defaultAutoCommit" value="false" />
		<property name="validationQuery" value="select 1 from dual"/>
		<property name="testOnBorrow" value="true"/>
		<property name="testWhileIdle" value="true"/> 
	</bean>

	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"/>
	</bean>

	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="configLocation">
			<value>classpath:ibatis/sqlMapConfig-jeaf-core.xml</value>
		</property>
	</bean>
	

	<bean id="sqlMapClientDaoSupport" class="org.springframework.orm.ibatis.support.SqlMapClientDaoSupport">
        <property name="sqlMapClient">
            <ref local="sqlMapClient"/>
        </property>
    </bean>

   <bean id="jempSysLoginDAO" class="com.skymount.jeaf.core.dao.impl.JempSysLoginDAOImpl"  parent="sqlMapClientDaoSupport" />
   <bean id="jempSysMenuDAO" class="com.skymount.jeaf.core.dao.impl.JempSysMenuDAOImpl"  parent="sqlMapClientDaoSupport" />
   <bean id="jempSysOperationDAO" class="com.skymount.jeaf.core.dao.impl.JempSysOperationDAOImpl"  parent="sqlMapClientDaoSupport" />
   <bean id="jempSysOperLogDAO" class="com.skymount.jeaf.core.dao.impl.JempSysOperLogDAOImpl"  parent="sqlMapClientDaoSupport" />
   <bean id="jempSysOperResDAO" class="com.skymount.jeaf.core.dao.impl.JempSysOperResDAOImpl"  parent="sqlMapClientDaoSupport" />
	
</beans>
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值