In spring-based applications, application objects exist in the spring container, container objects create them, assemble them, configure them, manage their entire life cycle, from survival to death. The spring container uses dependency injection management to form the components of the application, and he creates an association between the components that are col
From: http://jnotnull.iteye.com/blog/153475
In the preceding example, we can see that an error is thrown if no matching is found by setting the dependency-check = "object" attribute. This is the type check.
Let's take a look at the dependency Check Mode in bean 4 in Spring: simple, object, all, none.1 simple: Check the dependency of the basic type, struct type, and set.Java code
Http://www.springframe
The scope of the bean (each scope is in the same bean container)1.singleton: Singleton, refers to only one copy in a bean container (default)2.prototype: Create a new instance per request (per use), Destory mode does not take effect3.request: Each HTTP request creates an instance and only takes effect within the current request ( only available in the Web )4.sess
cycle : @PostConstruct : equivalent to init-method @PreDestroy : equivalent to destroy-method @PostConstruct Description @PostConstruct Span style= "font-family: the song Body;" The decorated method loads the servlet when run, And will only be called once by the server, similar to serclet inti () method. is @PostConstruct init () before the method runs. @PreConstruct Description was @PreConstruct Modified method is uninstalled on the server servlet when run, and wi
throws an exception when a failure is obtained, and the second way returns NULL.The third type: inherit from abstract class Applicationobjectsupport
Description: The Getapplicationcontext () method provided by the abstract class Applicationobjectsupport provides a convenient way to get to the ApplicationContext instance and get the bean in the spring container. When s
());10DifferentBean differentBean = (DifferentBean) context. getBean ("differentBean ");11System. out. printf ("ID: % d, Name: % s, Property: % s \ n ",12DifferentBean. getId (), differentBean. getName (), differentBean. getMyProperty ());13}14}If we run this class, we will get the following results:
1ID: 2, Name: superBean, Property: subBean2ID: 3, Name: superBean, Property: differentBeanwww.2cto.comWe learned from this example that if your bean cla
Spring provides automatic registration of bean definitions by scanning special annotation classes in the classpath. As with annotation-driven transactions, you need to turn on automatic scanning and register bean definition support in the following ways (Resources/chapter12/componentdefinitionwithannotation.xml):
Java code: Java code
The
The on "Annotation
The beans in the spring container have different scopes, starting with Singleton and prototype, but after 2.0, three more types are introduced: request, session, and global session, However, these three types can only be used in web apps.When you define a bean, you can specify the scope of the corresponding object by specifying the singleton or scope property of OrFirst, SingletonA
The scope property of the bean is Prototype,singleton,request, and several properties of the sessionWhen spring and struts2 are integrated, the STRUTS2 action is configured to scope= "prototype", which is for thread safety,The following is part of the struts2+hibernate+spring configuration file, which used to mimic the configuration of a well-written
By default, all beans in the Spring app context are created in singleton mode, that is, no matter how many times a given bean is injected elsewhere, it is the same instanceSpring defines a variety of scopes for beansSingleton Singleton only one instance of the bean is created throughout the applicationThe prototype Prototype creates a new
By default, all the beans in spring bean are single, that is, the single-profit mode. Scope = "Singleton"/>. Singleton indicates that only one bean object called mybean will be created in the spring container. All requests to this bean are processed by this object. This
A few days ago a colleague ran into a problem: normally according to Spring's official configuration, when struts2 and spring are integrated, the class attribute in the struts configuration file points to the Bean ID of the spring configuration, but when class points to the Classpath, can still inject service.
public class Loginaction extends actionsupport{
Priv
The way to create a Bean instance object is usually as follows:
Invoking the constructor to create a Bean instance
Invoking a static factory method to create a Bean instance
Invoking an instance factory method to create a Bean instance
To create a Bean
In spring, Initializingbean and Disposablebean are two token interfaces, a useful way for the bean to initialize and destroy certain behaviors when spring executes.
For the bean implementation Initializingbean, it will run Afterpropertiesset () after all the bean pr
There are 5 types of scope for spring beans:Singleton: When a bean is scoped to Singleton, there will only be one shared bean instance in the spring IOC container , and all requests to the bean As long as the ID matches the bean
instantiation is deferred, and if false, the singleton pattern Bean is instantiated immediately at startup. The default is False.Note: The Lazy-init property does not inherit from the quilt bean.6.autowireDetermines whether the properties of the bean are automatically assembled.The Autowire has 4 modes:
"No"
The
As the most popular and powerful lightweight framework in Java, Spring is warmly welcomed by programmers. It is necessary to have an accurate understanding of the spring Bean's life cycle. We usually use ApplicationContext as the spring container. Here, we are talking about the life cycle of the bean in ApplicationCont
Based on Java configuration options, you can write most of the spring without configuration XML, but with the help of several Java-based annotations explained. Starting with Spring3.0, we support the use of Java code instead of XML to configure spring, and Java-based configuration provides many of the benefits that spring relies on spring's Javaconfig project. By
Lin Bingwen Evankaka Original works. Reprint please specify the source Http://blog.csdn.net/evankakaBased on Java configuration options, you can write most of the spring without configuration XML, but with the help of several Java-based annotations explained. Starting with Spring3.0, we support the use of Java code instead of XML to configure spring, and Java-based configuration provides many of the benefit
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.