Home > Common Problem > body text

What layer annotation does component have?

anonymity
Release: 2019-05-08 14:03:01
Original
4034 people have browsed it

@component (Instantiate ordinary pojo into the spring container, which is equivalent to in the configuration file)

General Refers to various components, that is to say, when our class does not belong to various classifications (when it does not belong to @Controller, @Services, etc.), we can use @Component to annotate this class.

What layer annotation does component have?

Written below is the scanning component that introduces component

<context:component-scan base-package=”com.mmnc”>
Copy after login

where base-package is the package that needs to be scanned (including all sub-packages)

    1. @Service is used to label business layer components
  2. @Controller is used to label control layer components (such as actions in struts)
  3. @Repository is used to label data access components, that is, DAO components.
4. @Component generally refers to components. When components are difficult to classify, we can use this annotation for annotation.
@Service Public Class UserService Implements UserService {}

@RePOSITORY PUBLIC Class UserDao ImpleMents UserDao {} Getbean The default name is a class name (head letter). If you want to customize, you can @Service ("" " ***”) Specified in this way, this bean is singleton by default. If you want to change it, you can use @Service(“beanName”)

@Scope(“prototype”) to change it. You can use the following methods to specify the initialization method and destruction method (the method name is arbitrary): @PostConstruct public void init() { }

The above is the detailed content of What layer annotation does component have?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!