Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common notes in Spring

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the common notes on Spring". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the common notes on Spring.

1. Used to create bean objects

@ Component:

Function: injecting a normal class into the container is equivalent to configuring a bean tag, which usually appears on top of the class.

Attribute: value is used to specify the id of bean. When not written, there is a default value.

Three annotations derived from this annotation (all subclasses of Component):

@ Controller: comments commonly used for presentation

@ Service: commonly used in the business layer

@ Repository: commonly used in persistence layer

two。 Used to inject data

@ Autowired:

Function: automatically inject according to type. This can be achieved as long as there is a unique type match. If it is not unique, the name of bean will be looked up in the container as id, and the injection will be successful after finding it.

@ Qualifier:

Function: on the basis of automatic injection according to the type, then according to the id injection of bean. When injecting data into a class, it cannot be used independently; when injecting data into the parameter of a method, it can be used independently

Attribute: value is used to specify the id of the bean

@ Resource:

Function: directly according to the id injection of bean.

Attribute: name is used to specify the id of the bean

@ Value:

Purpose: used to inject data of basic types and String types, and el expressions can read the configuration in the properties file

Attribute: value, which specifies the data to be injected

At this point, I believe you have a deeper understanding of "what are the common annotations of Spring?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report