---
title: "spring 注解注入构造函数"
author: "lvjun106"
date: "2016-05-23T21:42:01Z"
tags: []
categories: ["开源软件"]
slug: "spring"
draft: false
lastmod: "2016-05-23T21:42:01Z"
id: 2300208
url: "https://lvjun106.iteye.com/blog/2300208"
---

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