Discover spring getter setter annotation, include the articles, news, trends, analysis and practical advice about spring getter setter annotation on alibabacloud.com
remove the set and get methods.
To achieve our goal of streamlining the program. You need to handle it like this:
* Add the following content to applicationcontext. xml:
Spring parses @ autowired through a beanpostprocessor, so to make @ autowired work, you must declare autowiredannotationbeanpostprocessor bean in the spring container in advance.
* Modify the bean method in the original spirng container.
spring2.5 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
@Resource By default is assembled by name, only if the bean that matches the name is not found to assemb
Description and Difference
spring4.1 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
A. @Resource By default is assembled by name, only if the bean that matches the n
, there is no ambiguity and it is recommended.
2. Automatic assembly according to type (Bytype). The spring container may find multiple beans of the same type as the bean that needs to be injected, so there is ambiguity, and the spring container does not know which bean to inject, and throws an exception.
3. Automatic assembly according to the constructor (constructor). This approach is more complex and doe
assembling beans (based on annotations)
L Annotation: is a class, using the @ annotation name
L Development: Use annotations instead of XML configuration files.
l annotation Use prerequisite, add namespace, let Spring scan contains annotation class
1. @Component
@Component
spring2.5 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to line-inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:
@Resource By default is assembled by name, only if the bean that matches the name is not found to assemb
")@javax. annotation.postconstruct
The initialization action that spring performs when the instance is created.
Location: Using the method level
Parameters: None@javax. Annotation.predestroy
The cleanup action that spring performs when the instance is destroyed.
Location: Using the method level
Parameters: None
Turn from: http://blog.csdn.net/zhang854429783/article/details/6785574
For a long time did not
Automatic annotation AssemblyWhen we assemble with annotations, we need to configure them in the XML file:Spring supports several different auto-annotation assemblies[email protected] : Spring will try to use the Bytype automatic assembly methodFor example: @autowired Public People (Language Language) {this. language =language;Language.say ();}@autowired public
/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 th
logic layer
@ Repository: Persistence Layer
2. Annotations exist.
Java code@ AutowiredUserService userService;
@ AutowiredUserService userService; 3. Corresponding setter Method
Java codePublic void setUserService (UserService userService ){This. userService = userService;}
Public void setUserService (UserService userService ){This. userService = userService;} 4. If it is an interface or an abstract class, the class must be unique; otherwise, an e
definition is equivalent to having the POJO extend the Spring predefined controller (such as Simp Leformcontroller, etc.).
@Resource
The setter method parameter that is used to annotate the attribute is derived from the spring Bean
@ModelAttribute
① bind request parameter to command object: When placed on the parameter of th
@AutowiredSpring 2.5 introduces @Autowired annotations that allow you to annotate class member variables , methods , and constructors , and complete the task of automating assembly . Use the @Autowired to eliminate the set, get method .Add to the member variable to omit the Get set method.But first, you have to configure Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor in the spring configuration file now.@Resource Ann
To reference the properties or to configure in XML, there are two configuration methods for referencing a single properties file, and multiple properties files
One, read a single properties file
In the spring configuration file, add the
Introduce the until namespace:
Xmlns:util= "Http://www.springframework.org/schema/util"
Xsi:schemalocation= "Http://www.springframework.org/schema/util
Http://www.springframework.org/schema/util/
spring2.5 provides annotations (annotation-based)-based configuration, which we can use to complete injection dependencies. In Java code, you can use @Resource or @autowired annotations to inject. Although both @resource and @autowired can be used to complete the injection dependency, there is a difference between them. First Look at:A. @Resource By default is assembled by name, only if the bean that matches the name is not found to assemble the injec
Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.Configuring Spring's annotation SupportThe above also mentions that using annotations to configure dependent objects is easier and easier, so here's a quick introduction to
To reference the properties or to configure in XML, there are two configuration methods for referencing a single properties file, and multiple properties files
One, read a single properties file
In the spring configuration file, add the
Introduce the until namespace:
Xmlns:util= "Http://www.springframework.org/schema/util"
Xsi:schemalocation= "Http://www.springframework.org/schema/util
Http://www.springframework.org/schema/util/
First or the configuration file for XMLXML version= "1.0" encoding= "UTF-8"?>Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/sc
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.