Object dependencies for the spring IOC container of the SSH Framework (3)

Source: Internet
Author: User
Tags ssh

I. Annotations to the object dependency relationship of IOC containers
1. Annotation Benefits: Annotations can simplify the configuration of the Spring IOC container!

2. Use the annotation steps:
1) First introduce the context namespace

xmlns:context= "Http://www.springframework.org/schema/context"

2) Turn on annotation scanning

<context:component-scan base-package= "Mfq.test" ></context:component-scan>


3) using annotations
The object is added to the IOC container by means of annotations.

Create objects and manipulate object dependencies, related annotations:
@Component specifies that an object be added to the IOC container

@Repository function with @component; used in the persistence layer
@Service function with @component; use in the Business logic layer
@Controller function with @component; Use in the control layer

@Resource attribute Injection

3. For example:
Form one: Use only @component and @resource
1) Userdao.java

2) Userservice.java

3) Useraction.java

4) test class App.java

Form II: Use of proprietary annotations
1) Userdao.java

2) Userservice.java

3) Useraction.java

4. Summary:
1) using annotations, you can simplify the configuration, and you can add objects to the IOC container and Process dependencies (DI).
2) annotations can be used in conjunction with the XML configuration.

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.