當前位置:編程學習大全網 - 源碼下載 - spring+ibatis在spring配置文件中註入sqlmapclient時,壹直報錯,詳情代碼見下面

spring+ibatis在spring配置文件中註入sqlmapclient時,壹直報錯,詳情代碼見下面

spring3.0註入sqlMapClient的幾種方式:

bean定義:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver" />

<property name="url" value="jdbc:mysql://localhost:3306/cms" />

<property name="username" value="root" />

<property name="password" value="19860619" />

</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

<property name="configLocation">

<value>classpath:/context/ibatis/sqlMapConfig.xml

</value>

</property>

<property name="dataSource">

<ref bean="dataSource" />

</property>

</bean>

a.在context中裝載sqlMapClient並建立sqlMapClientfactory,每次執行sql操作都從factory中獲取sqlMapClient.factory獲取bean方法:

WebApplicationContext wac = ContextLoader

.getCurrentWebApplicationContext();

SqlMapClient sqlMapClient = wac.getBean("sqlMapClient",

SqlMapClient.class);

b.在每個DAO中使用spring註解註入sqlMapClient:

@Autowired

@Qualifier("sqlMapClient")

private SqlMapClient sqlMapClient;

c.創建BaseDao繼承SqlMapClientDaoSupport,所有DAO都繼承BaseDao.BaseDao中註入sqlMapClient:

@Autowired

@Qualifier("sqlMapClient")

public void setSqlMapClientForAutowired(SqlMapClient sqlMapClient) {

super.setSqlMapClient(sqlMapClient);

}

該方法實際上是使用了sqlMapclientTemplate並向template註入sqlMapClient。

  • 上一篇:amo量柱公式
  • 下一篇:求關於"盈利質量分析"的文獻綜述
  • copyright 2024編程學習大全網