`

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>
分享到:
评论

相关推荐

    SqlMapClient对象.pdf

    通过调用`SqlMapClient.startTransaction()`开启事务,`SqlMapClient.commitTransaction()`提交事务,或者`SqlMapClient.rollbackTransaction()`回滚事务。 6. **异常处理**: 在初始化SqlMapClient或执行数据库...

    SqlMapClient对象.docx

    `SqlMapClient`对象是iBatis的核心接口,它提供了对数据库进行CRUD(Create、Read、Update、Delete)操作的能力,并且支持事务管理。由于`SqlMapClient`是线程安全的,因此在实际应用中,通常会将其作为单例模式来...

    传智播客ibatis视频教程源代码

    private static SqlMapClient sqlMapClient = null; static { try { Reader reader = com.ibatis.common.resources.Resources.getResourceAsReader("com/itcast/SqlMapConfig.xml"); sqlMapClient = ...

    ibatis批量处理

    SqlMapClient sqlMapClient = sqlMapClientTemplate.getSqlMapClient(); try { // 开始事务 sqlMapClient.startTransaction(); // 开始批处理 sqlMapClient.startBatch(); for (Reply reply : replyList) {...

    Spring高版本对ibatis的支持

    &lt;bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"&gt; &lt;value&gt;classpath:SqlMapConfig.xml &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt; ...

    Sping+ibatis

    首先,我们需要在项目中引入iBATIS的相关库,并在Spring配置文件中定义SqlMapClient。这通常通过`&lt;bean&gt;`标签实现,如下所示: ```xml &lt;bean id="sqlMapClient" class="org.springframework.orm.ibatis....

    ibatis_教程_详解.doc

    SqlMapClient可以通过SqlMapClientBuilder类来构建,这个类提供了加载XML配置文件并初始化SqlMapClient的方法。 Ibatis的配置文件中,你可以定义SQL语句的映射,这些映射位于独立的XML文件中,通常命名为xxxSqlMap....

    Spring+iBatis整合详解

    以上配置中,`txAdvice`定义了不同的方法名称对应的事务传播行为,比如所有的“add”、“del”和“update”方法都使用REQUIRED传播行为,而其他方法默认为只读操作。 ##### 3. SqlMapClient配置 接下来,需要配置`...

    SPRING IBATIS 保留IBATIS事务的配置方式

    SqlMapClient sqlMapClient = (SqlMapClient) applicationContext.getBean("sqlMapClient"); ``` 2. **开启事务**:使用SqlMapClient提供的方法开启一个新的事务。 ```java Transaction tx = new Transaction...

    ibatis2.0开发指南 ibatis开发必备

    - SqlMapClient是iBATIS的核心接口,提供执行SQL语句的方法,如`queryForObject()`, `queryForList()`, `insert()`, `update()` 和 `delete()`。 - 示例代码展示了如何使用SqlMapClient进行CRUD操作。 7. **OR...

    ibatis 使用简单配置

    下面是创建`SqlMapClient`实例的一个示例类`SqlMapUtil`,该类通过静态方法`getSqlMapClient()`返回`SqlMapClient`实例。 ```java import java.io.IOException; import com.ibatis.common.resources.Resources...

    Ibatis应用事例

    - **SqlMapClient 实例化**:通过 `SqlMapClientBuilder` 创建 `SqlMapClient` 实例,这是Ibatis的核心组件之一。 - **QueryForList 方法**:用于查询所有记录,其中 `"queryAll"` 是映射文件中 `&lt;select&gt;` 元素的 `...

    ibatis多对多关系(详细)

    public StudentDAO(SqlMapClient sqlMapClient) { this.sqlMapClient = sqlMapClient; } public List&lt;Student&gt; getStudentsByTeacherId(String teacherId) { return sqlMapClient.queryForList(...

    ibatis开发指南

    SqlMapClient sqlMapClient = new SqlMapClientBuilder().buildWithoutXMLReader(new FileInputStream("SqlMapConfig.xml")); // 执行查询 List&lt;YourEntity&gt; list = sqlMapClient.queryForList("selectYourEntity")...

    记一次Ibatis的意外发生.docx

    nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'。这种错误是由于SqlMapConfig.xml文件的配置...

    IBATIS实用记录

    3.3 SQLMAPCLIENT基本操作示例 6 3.3.1 数据写入操作(insert, update, delete) 6 3.3.2 数据查询 (select) 7 3.3.3 在指定对象中存放查询结果(select) 7 3.3.4 执行批量查询 (select) 7 3.3.5 关于AutoCommit 7 ...

    springmvc-ibatis

    &lt;property name="sqlMapClient" ref="sqlMapClient"/&gt; &lt;!-- 配置 transactionManager事物管理--&gt; &lt;!-- Spring AOP config配置切点 --&gt; (* com.org.service.*.*(..))" id="bussinessService" /...

    struts+spring+ibaits配置详解

    private SqlMapClient sqlMapClient; @Autowired private PlatformTransactionManager transactionManager; public void insertUser(User user) { TransactionTemplate template = new TransactionTemplate...

    ibatis的两种方式实现批处理.doc

    在批处理操作中,需要使用SqlMapClient的startTransaction()方法来启动事务,startBatch()方法来启动批处理,然后执行批处理操作,最后使用executeBatch()方法来执行批处理,commitTransaction()方法来提交事务。...

Global site tag (gtag.js) - Google Analytics