Spring Annotation Feature Notes

Source: Internet
Author: User

@Autowired
@Autowired annotations can be used to automatically connect beans in setter methods. Match in type mode.
A constructor @Autowired explains that when you create a bean, the constructor is automatically connected even if you do not use the element configuration bean in the XML file.
 
 

Mapping mode 1 using @autowired for variables, injecting other beans into the XML, you can omit the member variables of the configuration class from the injected object

Mapping mode 2 using @autowired for the set method and injecting other beans into the XML, you can omit the member variables of the configuration class from the injected object

Mapping mode 3 using @autowired for constructors and injecting other beans into the XML, you can omit the member variables of the configuration class from the injected object

Need to cooperate when using

<!--the beanpostprocessor will function automatically and automatically inject the Bean labeled @Autowired

<bean class= "Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

@Resource
function equal to @autowired, match in name mode
The explanation for @autowired and @resource is better than a reference http://www.cnblogs.com/xrq730/p/5313412.html
@Required
@Required comment The setter method applied to the Bean property, which indicates that the affected bean properties must be placed in the XML configuration file at configuration time, or the container throws a Beaninitializationexception exception.
@Component
This annotation tells the spring container to pick the beans while component-scanning is running.
 
  
 
 
@Repository
For DAO implement, you can automatically scan for adding DAO's beans by adding @repository
@Service
A implement that applies to a service (typically one serving is an abstraction of a DAO's services, directly invoking the DAO implementation Class), and can be implemented by adding @service to automatically scan the bean that adds the service
Application @[email protected] Reference
Need to cooperate when using<context:component-scan base-package="javabeat.net"/>
http://javabeat.net/spring-annotations-component/
@Controller
Role: In the Springmvc application, tell the server that this class is the controller in MVC, which can receive user requests to process user requests
@Qualifier
When there are two implementation classes for an interface, you must use @qualifier to specify which implementation class to inject
Other annotations are described in other pages.
@Import
@PostConstruct
@PreDestroy
@Target
@Retention
@Configuration
@Bean
@Scope
Reference http://blog.csdn.net/zhang854429783/article/details/6785574

Spring Annotation Feature Notes

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.