Spring (4) Bean injection (Spring Bean injection)1. constructor Injection
Definition: You can use constructors to set dependencies.
Advantages and disadvantages:
Complete dependency creation while constructing objects
If there are many associated objects, you have to add too many parameters to the constructor.
Base index: if the specified index starts from 0, type is used to specify the type.
Entity class:
Original: CSS Learning Note: Overflow text ellipsis (text-overflow)In CSS3, the basic syntax for the Text-overflow property is as follows:
Clip: Indicates that the omitted text is not displayed and is simply trimmed.
Ellipsis: Indicates that an ellipsis is displayed when an object text overflows, and the caret insertion position is the last character
Spring basics-automated bean assembly and spring basics bean
As mentioned in the previous blog post about Spring's IOC container, although the container is powerful, the container itself is just an empty shell. We need to take the initiative to put the Assembly object and tell it the collaboration relationship between objects, then the container can use its magic as instructed to complete
SpringMVC conflicts with existing, non-compatible bean definition of same name and class solution, springmvc obtains beanCause
Recently, a colleague from the project team encountered a problem. The module he was responsible for, SpringMVC Controller, and the Controller class names of other modules were duplicated, causing the whole project to fail.
The following error is reported in the background:
××Controller' for
where Java holds object instances.Heap Overflow can be divided into the following two cases, both of which throw the Outofmemoryerror:java heap space exception:1. Memory leaksA memory leak is when an object instance is still referenced after it has been created and used, not released by garbage collection, and accumulates until there is no remainingMemory is available.If memory leaks, we want to find out how the compromised object was referenced by G
Memory overflow out of memory, which means that the program does not have enough memory space for it to use when applying for memory, and it appears out of the memory; For example, an integer is applied, but the number that has long to save is the memory overflow.
Memory leak memory leak, refers to the program in the application of memory, can not release the requested memory space, a memory leakage hazard
If you see stateful session beans and stateless session beans, you will first think of them here.StatusWhat does it mean?
1,Stateful)
The status of each client can be maintained between different method calls.
The connection with the client must be maintained, so the overhead is higher.
It can also be understood as stateful because it has the storage capability, that is, at least one attribute to identify its current status, for example:
public class Stateful {private String name;public Statefu
I found it when I met this problem. Springmvc @RequestBody problem: Unrecognized field, not marked as ignorable This article says: @JsonIgnoreProperties (Ignoreunknown = True), after the annotation is written on the class, fields that do not exist in the class are ignored, and the current needs are met. This annotation can also specify the fields to ignore. Here's how to use it: @JsonIgnoreProperties ({"Internalid", "Secretkey"}) The specified field is not serialized and deserialized. But my
What is the difference between message driven beans and stateless session beans? -What is the difference between a message-driven bean and a stateless Session Bean?
In several ways, the dynamic creation and allocationMessage-driven bean instances mimics the behavior of stateless sessionEJB instances, which exist only for the duration of a participant MethodCall.
Maintain the user status-Use of session bean in Spring and user status bean
We all know that in web development, once a user logs on to the system, the system must maintain the user's status before logging off, in this way, he can see his content (such as the personal homepage and message ).
So how to maintain the user status? Spring provides a bean scope mechani
Gets the context of the application, gets the bean object and related informationpackagecn.sccl.common.util;importjavax.servlet.http.httpservletrequest;import org.springframework.beans.beansexception;import org.springframework.beans.factory.nosuchbeandefinitionexception;import Org.springframework.context.applicationcontext;importorg.springframework.context.applicationcontextaware ;importorg.springframework.web.context.request.requestcontextholder;impo
Spring also has an abstract bean. You only need to set the abstract attribute to true in the configuration file. It does not configure the class attribute because it will not be instantiated. When the bean of another spring inherits the abstract bean, You need to configure its parent attribute. If the parent bean is co
Sometimes you need to get a spring bean object on your own as needed in your new object, or in some Util method or property, to do some work, but because your new object and Util method are not managed by spring, if you use it directly on the property that you depend on @Autowiredyou will be able to report an error that cannot be injected, or it will not be reported, but a null pointer exception is quoted when used. All in all, it cannot be injected b
Reference: http://hi.baidu.com/victorlin23/blog/item/45ba7d1b2ccbced8ad6e7595.html
The bean defaults to a single example.
If you do not want a single example, you need the following configuration:
Singleton is to configure whether the bean is a single case, and if not, the default value is true.
Annotations:
Spring Bean life cycle
The scope of the 1.
MethodInvokingFactoryBean factory bean can inject the returned values of the specified method into the attribute values of the target Bean. MethodInvokingFactoryBean is used to obtain the returned values of the specified method. This method can be a static method.
It can also be an instance method.
The returned value of the method can be either injected to the specified attribute of the specified
All Spring beans are single-instance by default. If multiple instances are required, the configuration is as follows:
Scope
Definition
Singleton
In each spring container, a Bean defines only one object instance (default)
Prototype
Allow beans to be instantiated any time
Reqyest
In an HTTP request, each Bean defines an instance. This scope is only valid i
Novice in writing program, must be adventurousness, and must have patience, do not compromise, do not understand on the book, online search data, ask friends, resolutely carried out in the end.
Recently has been with the knowledge of the ASP in the groping forward, a run bumpy, since needless to say. Anyway
Establish a login system that requires the following purposes.
1, the user through the bean to authenticate and get the user information.
2, r
Spring IOC The bean configured by default is a singleton pattern, that is, only a bean instance is created for the Bean node. The Bean object for each get is an instance object.In Spring, you can set the scope of the bean in the scope property of the By default, Spring creat
Spring bean can inherit the beanfactory interface and implement interfaces such as getbean () and issingleton. The bean is configured in the configuration file, which is characterized by that when the caller calls the bean, the returned bean is not the bean, but its product,
Scope of the BeanSpecifies the scope of the bean element by specifying scope for the bean when the bean is configuredThe default value for scope is Singleton, which is singleton mode, in one applicationcontext, each time the Getbean () method is called, the same bean is obtained.If you want to make each fetch a differe
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.