In general, we register a bean in spring and directlyid= "WebSocket" class= " Com.sdyy.common.spring.websocket.WebsocketEndPoint "/>This creates an object bean for us, using the Websocketendpoint construction method (which is no parameter).———————————————————————————— Dividing line —————————————————————————————————————————————But there is another way to register beans with the
: Construction methodExecutive Initanddestroyseqbean:postconstructExecutive Initanddestroyseqbean:afterpropertiessetExecutive Initanddestroyseqbean:init-methodExecutive Initanddestroyseqbean:predestroyExecutive Initanddestroyseqbean:destroyExecute initanddestroyseqbean:destroy-method.We introduce the relevant methods before and after instantiation of spring Bean:@PostConstruct Init-method destroy-method afterpropertiesset () @PreDestroy Destroy execut
Three ways to implement bean instantiationFirst: Create using the parameterless construction method of the class (common importance)The first instantiation method is most commonly used, and the class is instantiated by calling the parameterless construction method to create it. The sample code is as follows:Package Spring.com.userservice;public class UserService {public UserService () {//The method is an argument-free method}public void AddUser () { S
http://blog.csdn.net/anyoneking/article/details/5182164In spring's bean configuration, there are two scenarios:[XHTML]View Plaincopy
Bean id="Testmanager" class="Com.sw.TestManagerImpl" scope= "singleton"/>
Bean id="Testmanager" class="Com.sw.TestManagerImpl" scope= "prototype " />
Of course, the scope has more than two values, in
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.
Examples on the official website
JSON-lib is a Java class package used to convert beans, maps, and XML into JSON and convert JSON back to bean and dynabean.: Http://json-lib.sourceforge.net/The third-party package is also required:Org. Apache. commons (version 3.2 or later)Org. Apache. oroNet. SF. ezmorph (ezmorph-1.0.4.jar)Nu. XOM1. ListJava code
Boolean[] Boolarray =NewBoolean[] {True,False,True};
Jsonarray jsonarray1 = jsonarray. fromobject (boo
A bug occurred while testing AOP:Run after you configure the spring configuration file, test case, and error:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException:No unique bean of type [ Mycom.test.aop.ArithmeticCalculator] is defined:expected single Bean but found 0: at
Org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean (Defaultlistableb
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
Spring -- configure bean through annotation, spring -- bean
Spring configures bean through AnnotationBean configuration based on AnnotationConfigure bean Attributes Based on AnnotationsScan components in classpathComponent scan: Spring can automatically scan from classpath to detect and instantiate components with spec
Common annotations for Spring beans@Component: usually annotations, available for any bean@Repository: Typically used to annotate the DAO layer, which is the persistence layer@Service: Typically used to annotate service tiers, or services tiers@Controller: Typically used to annotate the controller layer, which is the control layerAutomatic detection of classes and the registration of beansDefining beansThe bean
In Spring configuration, the bean class uses the factory Bean meaning for parsing. springbean
Parsing the meaning of factory bean used by Bean class in Spring Configuration
Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)
This article follows the "signature-non-commercial use-consistency" creati
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.