Spring 3.0 It's such a simple reading note.

Source: Internet
Author: User

In general, most of the beans in the spring container are single-instance, so it is generally not necessary to specify a name for the bean through the Value property of the annotation @repository, @Service, @Component, etc. There is no need to use @qualifier to inject by name.

@Autowired are used in the following ways:

Labeling a class variable

@Autowired

Private Logdao Logdao;

Labeling A class method

To label a collection class (a property of a class)

@Autowired

Private list<plugin> plugins;

@Autowired
@Qualifier ("Testing")
Private Foodao Foodao;

Foodao corresponding Beanid is not necessarily foodao, there may be other.

Foodao has two implementation classes: Stubfoodao and Wjfoodao, see below

@Qualifier ("okdahello")
Private Foodao Foodao;

The Okdahello above can correspond to

@Repository ("Okdahello")
@Qualifier ("Testing")
public class Wjfoodao implements Foodao

can also correspond to

@Repository
@Qualifier ("Testing")
@Qualifier ("Okdahello")
public class Wjfoodao implements Foodao

@Qualifier ("Okdahello") or @Repository ("Okdahello") is all OK
@Repository ("Okdahello") can change Beanid.

Spring 3.0 It's such a simple reading note.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.