sqlMapClient is required

18:00:18,417 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'objectidsDAO' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: sqlMapClient is required
Caused by: java.lang.IllegalArgumentException: sqlMapClient is required

here is one possible way to do it...(for using Ibatis

 

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/testing" />
        <property name="username" value="someUsername" />
        <property name="password" value="somePassword" />
    </bean>  
     <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation" value="WEB-INF/IbatisSqlMap-Config.xml" />
        <property name="dataSource" ref="dataSource" />       
    </bean>
    <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
         <property name="sqlMapClient" ref="sqlMapClient" />
</bean>

 and then make sure the sqlMapClientTemplate is being injected into your DAO objects...

 

public class SomeIbatisDao extends SqlMapClientDaoSupport implements SomeDao
{
    public List someMethodUsingIbatis(int id)
    {
        getSqlMapClientTemplate().queryForList("queryNameInIbatisSqlXmlFile", id);
    }
    public void setSqlMapClientTemplate(sqlMapClientTemplate   sqlMapClientTemplate)
    {
        this.sqlMapClientTemplate = sqlMapClientTemplate;
    }
    private SqlMapClientTemplate sqlMapClientTemplate;
}

 -----------------------------------------------------------------------------------------------------------------------------

以下是我的实际应用中的解决方案

 

public class PubDao extends SqlMapClientDaoSupport 
{
	protected static final int PAGE_SIZE = 4;
	protected SqlMapClientTemplate smcTemplate1 = this.getSqlMapClientTemplate();
	public PubDao(){ }
}

 

public class BsjdcbyltjjuDaoImpl extends PubDao implements BsjdcbyltjjuDao {
	public List getBsjdcbyltjjuByVo() {
		List list = smcTemplate1.queryForList("getBsjdcbyltjjuAll");
		return list;
	}...
}

 

applicationContext.xml

 

<!-- Spring iBatis SqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="classpath:ibatis/sql-map-config.xml" />
  <property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource"></property>
</bean>

<bean id="pubDao" class="com.suntendy.framework.sjjh.dao.PubDao">
   <property name="sqlMapClient">
       <ref bean="sqlMapClient"/>
   </property>
</bean>

 bsjdcbyltjju.xml

 

<bean id="bsjdcbyltjjuDao" class="com.suntendy.framework.sjjh.dao.impl.BsjdcbyltjjuDaoImpl" parent="pubDao">
</bean>
<bean name="bsjdcbyltjjuService" class="com.suntendy.framework.sjjh.service.impl.BsjdcbyltjjuServiceImpl"> 
        <property name="bsjdcbyltjjuDao"> 
            <ref bean="bsjdcbyltjjuDao"/> 
        </property> 
</bean>
<bean id="bsjdcbyltjjuAction" class="com.suntendy.framework.sjjh.action.BsjdcbyltjjuAction">
	<property name="bsjdcbyltjjuService">
		<ref bean="bsjdcbyltjjuService" />
	</property>	
</bean>

你可能感兴趣的:(DAO,mysql,bean,jdbc,ibatis)