您的位置:首页 > 编程语言 > Java开发

spring 注解注入构造函数

2016-05-23 21:42 453 查看
package cn.outofmemory.hellspring.transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class CustomerDao extends SqlMapClientDaoSupport {

@Autowired(required = true)
public CustomerDao(@Qualifier(value="sqlMapClient4A") SqlMapClient sqlMapClient) {
super.setSqlMapClient(sqlMapClient);
}

}

 

注意Qualifier的位置必须放在参数的前面,而不能放在构造函数的前面。 这是合理的如果一个构造函数有多个参数的话把Qualifier放在构造函数前面就会有歧义。

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: