XML configuration and autowired blending in spring

Source: Internet
Author: User

1. Mixing of classes:

Configuration in the configuration file:

<bean id= "A" class= "COM.AB.CC.A"/>

Configuration in a class

@Autowired

A;

The benefits of this can be reduced Get/set method

[email protected] and @resource the difference

Autowired By default is automatically assembled according to Bytype, so there are multiple types of XML or annotation of a class when the error, you can add @qualifier annotations, specify the name. This is spring comes with, when the frame, to spring;

@Autowired
@Qualifier ("Userserviceimpl")
Public Iuserservice UserService;

Or

@Autowired
public void Setuserdao (@Qualifier ("Userdao") Userdao Userdao) {
This.userdao = Userdao;
}

Resource by default is automatically assembled according to the byname, this is the Java comes with, when changing the frame, do not need spring.

@Resource

Private car car;

3. In the XML configuration file, the previous <context:component-scan/> configuration will be overwritten by the <bean id= ""/> Configuration in the following case, if there is the same configuration

XML configuration and autowired blending in spring

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.