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.startTransaction()`开启事务,`SqlMapClient.commitTransaction()`提交事务,或者`SqlMapClient.rollbackTransaction()`回滚事务。 6. **异常处理**: 在初始化SqlMapClient或执行数据库...
`SqlMapClient`对象是iBatis的核心接口,它提供了对数据库进行CRUD(Create、Read、Update、Delete)操作的能力,并且支持事务管理。由于`SqlMapClient`是线程安全的,因此在实际应用中,通常会将其作为单例模式来...
private static SqlMapClient sqlMapClient = null; static { try { Reader reader = com.ibatis.common.resources.Resources.getResourceAsReader("com/itcast/SqlMapConfig.xml"); sqlMapClient = ...
SqlMapClient sqlMapClient = sqlMapClientTemplate.getSqlMapClient(); try { // 开始事务 sqlMapClient.startTransaction(); // 开始批处理 sqlMapClient.startBatch(); for (Reply reply : replyList) {...
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <value>classpath:SqlMapConfig.xml <property name="dataSource" ref="dataSource"></property> ...
首先,我们需要在项目中引入iBATIS的相关库,并在Spring配置文件中定义SqlMapClient。这通常通过`<bean>`标签实现,如下所示: ```xml <bean id="sqlMapClient" class="org.springframework.orm.ibatis....
SqlMapClient可以通过SqlMapClientBuilder类来构建,这个类提供了加载XML配置文件并初始化SqlMapClient的方法。 Ibatis的配置文件中,你可以定义SQL语句的映射,这些映射位于独立的XML文件中,通常命名为xxxSqlMap....
以上配置中,`txAdvice`定义了不同的方法名称对应的事务传播行为,比如所有的“add”、“del”和“update”方法都使用REQUIRED传播行为,而其他方法默认为只读操作。 ##### 3. SqlMapClient配置 接下来,需要配置`...
SqlMapClient sqlMapClient = (SqlMapClient) applicationContext.getBean("sqlMapClient"); ``` 2. **开启事务**:使用SqlMapClient提供的方法开启一个新的事务。 ```java Transaction tx = new Transaction...
- SqlMapClient是iBATIS的核心接口,提供执行SQL语句的方法,如`queryForObject()`, `queryForList()`, `insert()`, `update()` 和 `delete()`。 - 示例代码展示了如何使用SqlMapClient进行CRUD操作。 7. **OR...
下面是创建`SqlMapClient`实例的一个示例类`SqlMapUtil`,该类通过静态方法`getSqlMapClient()`返回`SqlMapClient`实例。 ```java import java.io.IOException; import com.ibatis.common.resources.Resources...
- **SqlMapClient 实例化**:通过 `SqlMapClientBuilder` 创建 `SqlMapClient` 实例,这是Ibatis的核心组件之一。 - **QueryForList 方法**:用于查询所有记录,其中 `"queryAll"` 是映射文件中 `<select>` 元素的 `...
public StudentDAO(SqlMapClient sqlMapClient) { this.sqlMapClient = sqlMapClient; } public List<Student> getStudentsByTeacherId(String teacherId) { return sqlMapClient.queryForList(...
SqlMapClient sqlMapClient = new SqlMapClientBuilder().buildWithoutXMLReader(new FileInputStream("SqlMapConfig.xml")); // 执行查询 List<YourEntity> list = sqlMapClient.queryForList("selectYourEntity")...
nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'。这种错误是由于SqlMapConfig.xml文件的配置...
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 ...
<property name="sqlMapClient" ref="sqlMapClient"/> <!-- 配置 transactionManager事物管理--> <!-- Spring AOP config配置切点 --> (* com.org.service.*.*(..))" id="bussinessService" /...
private SqlMapClient sqlMapClient; @Autowired private PlatformTransactionManager transactionManager; public void insertUser(User user) { TransactionTemplate template = new TransactionTemplate...
在批处理操作中,需要使用SqlMapClient的startTransaction()方法来启动事务,startBatch()方法来启动批处理,然后执行批处理操作,最后使用executeBatch()方法来执行批处理,commitTransaction()方法来提交事务。...