A brief explanation of spring annotations

Source: Internet
Author: User

@Scope ("prototype")

If the action does not @scope ("prototype"), it is possible to report that xxxaction error is not found! Writing this means that each request is re-created with an action corresponding to Singalon, commonly known as " multiple cases ".

@Service ("AAAAA"). This bean is "singleton" by default.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------

@Service

Used for labeling business layer components, note the annotations in the implementation class, and do not comment on the interface. Use an excuse when referencing in action

Interface

Interface implementation

In action

@Controller

For labeling control-layer components, such as action in struts

@Repository

For labeling data Access Components, DAO components

@Component

We can use this annotation to annotate components when they are poorly categorized. The previous 3 comments and @Component are equivalent, but from the name of the annotation class it is easy to see that the 3 annotations correspond to the persistence layer, the business layer, and the control layer (the WEB layer), respectively.

--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------

@Autowired

The getter () and setter () methods are not required, and spring can be automatically injected

@Qualifier

If more than one implementation class is available for this tag, specify which implementation class to inject, otherwise you can omit, write only @autowired

--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------

Configuring annotations in the Spring container

<context:annotation-config/>
<context:component-scan base-package= "Com.xxx.xxx.base" >
<context:include-filter type= "Annotation"
expression= "Org.springframework.stereotype.Repository"/>
</context:component-scan>

,,,,,,,,

<context:annotation-config> is used to activate beans that have already been registered in the Spring container(either through XML or through the package Sanning way) above the annotations.

<context:component-scan> in addition to having <context:annotation-config> functions,<context:component-scan> You can also scan and register JavaBean under the specified package.

with <context:component-scan>, another <context:annotation-config/> tag can be removed at all, because it is already included.

<context:component-scan> provides two sub-tags:<context:include-filter> and <context:exclude-filter> filters introduced and excluded by each representative.

Context:include-filter for include, I understand that in addition to scanning the subclasses below the Base-package package, the package behind expression is also scanned.
Context:exclude-filter for exclude, I think even if the package behind expression is under base-package, it does not scan.

Quoted a lot of

A brief explanation of spring annotations

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.