ITeye博客

spring 注解注入构造函数

lvjun106 · 2016-05-23 21:42 · SPRING · SPRING MVC · 开源软件 · Markdown

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放在构造函数前面就会有歧义。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。