The life cycle of a Spring bean is easy to understand. When a bean is instantiated, it may need to perform some initialization to convert it to a usable state. Similarly, when a bean is no longer needed and removed from the container, some cleanup work may also need to be done.However, there are activities that take place between the instantiation of the
Read the spring IOC part of the source code for some time, through continuous single-step debugging and reference materials, the spring container bean management has a certain understanding. From the point of view of several states of beans, this paper studies the IOC container.First, raw materialsThe bean definition configuration (or annotations) in XML, and Java code BeanID= "book"name= "book"class= "C
Name of Bean in spring1, each bean can have an id attribute, and according to the ID in the IOC container to find the bean, the id attribute value must be unique in the IOC container;2, you can not specify the id attribute, only specify the fully qualified class name, such as:The bean needs to be obtained through inter
How does the Spring IOC container instantiate the bean? Traditional applications can instantiate beans by using new and reflective methods. The spring IoC container needs to use the reflection mechanism to create the bean based on the configuration metadata in the bean definition. There are several ways to create a bean
[Spring] BeanFactory parses bean details, beanfactorybeanIn this article, we will talk about the BeanFactory bean parsing process in the Spring framework. This article has been published in the original article of the small series. To view the original text, you can click the original text to view it, let's first look at a basic bean definition and use in Spring.
In essence, the spring container is a very large factory, and the bean in the spring container is the product of the factory. What products can spring containers generate depends entirely on the configuration of the developer in the configuration file.
The
BeansElement attributes
Attribute name
Description
Deafult-Lazy-init
Specifies the default delayed initialization behavior of all beans configured under the
Reprinted:
Http://blog.csdn.net/lifeshow/archive/2006/11/16/1388209.aspxLet's take a look at this discussion:
Http://www.javaeye.com/post/325403
Lazy instantiation
Bean
Applicationcontext
By default, all Singleton instances are pre-instantiated as early as possible at startup.
Bean
. The so-called "pre-instantiation" refers
Applicationcontext
During the initialization process, the Instance tries its best t
Spring is a lightweight bean container solution. The core solution is bean creation and bean dependency injection.There are three methods for constructing bean instances in spring.(1) construct an instance through the constructor. (2) construct using static factory methodsBean instance. (3) construct a
One: The Bean configuration formBased on XML configuration: Create a applicationcontext.xml file in the SRC directory, where it is configured.Annotation-based configuration: When you create a bean class, the content is injected with annotations. (This is not good because the annotations are also in the code and are too fragmented)Two: The way to find beansCreate a bean
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 SetLanguage (languagelanguage) {this. language =language;Language.say ();}Generally for the bean
Second, the annotation is divided into two categories:
1, a class is the use of beans, that is already configured in the XML file with the bean to use, complete the attributes, methods of assembly; For example, @autowired, @Resource, can be passed through the Bytype (@Autowired), ByName (@Resource) The way to get the bean;
2, a class is registered Bean, @Compon
Eliminates redundant parent-class configuration, such as transaction management:
Because there is no target attribute in the declaration, it must be declared as an abstract class, that is, abstract = true;
Attention
By default,ApplicationContext (not beanfactory) instantiates all singleton beans. So it's important to note that if you just want to use a (parent) bean definition as a template and it specifies the class attribute, you have to set
; bean> # #基于注解的bean管理 # 1. Instantiating an object based on annotations (recommended) instantiating objects and dependency injection in two ways: Configuration file, annotations 1. Scan package (profile) 2. Annotations for specific functions ( instantiation function) @Component general annotations: instantiating objects @ Controller: Instantiating objects of the control layer
Summary of Spring Bean properties and child elements usage2016-08-03 00:0097 people readComments (0)CollectionReport Category:Springspringmvc(+) Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.Spring framework mainly has four kinds of tag beans, alias, import, beans, where the bean tag is the basis of other tags, this article mainly on the
We know that in spring2.0, there are two types of beans except singleton and prototype. By default, three types of beans are added: request, session, and global session. The added beans are mainly used in Web applications. This article does not want to analyze the usage of the three types of beans, but simply analyzes the implementation principle of the framework.
Spring2.0 adds a scope interface to indicate the bean range.
Public interface scope {
Ob
In addition to component scanning and automatic assembly, there are Java code-based assembly and XML-based assembly.There are some scenarios where we cannot use automatic assembly, for example, we are going to assemble the components in our third-party library into our application, and the automatic assembly is not valid because automatic assembly can only scan packages in this application.At this point we're going to choose between code-based assembly and XML-based assembly, before we say that
;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classTestspringxml { Public Static voidMain (string[] args)throwsperformanceexception {//assembling the Spring.xml configuration fileApplicationContext CTX =NewClasspathxmlapplicationcontext ("Spring.xml"); //The bean that gets the claim from the spring containerPerformer performer = (performer) Ctx.getbean ("Duke"); //methods for executing beansPerformer.perform (); }}f
Bromon originality, please respect copyright
After so long mixing in the Java World, I have been asked the most questions since I broke away from the deep-rooted Java cainiao community. The first question is "What books should I read when I learn java ", the second is "What is J2EE ". The first question is confusing, and the second question is hard to explain. The J2EE framework is huge, with 13 core technologies. It is too complicated to explain. The concept of J2EE is often abused. What is a J
Spring core learning (5) inject beans into Bean-Parse dependencies, beanbean-
Preface: start to learn the core idea of Spring and learn it through a simplified version of Spring code.
Content: 1. BeanReference-save Bean reference. 2. Call createBean ()-lazy-init in getBean. This time we used Bean injection in Bean. He
What exactly is the bean's life cycle like in spring?1. The container looks up the bean's definition information and instantiates it2. Using dependency injection, spring configures all the Bean's properties according to the Bean definition information3. If the bean implements the Beannameaware interface, the factory calls the Bean's Setbeanname () method to pass the Bean's ID4. If the
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.