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?
The following content is translated from: https://www.tutorialspoint.com/springmvc/springmvc_beannameurlhandlermapping.htmDescription: The sample is based on spring MVC 4.1.6.The following example shows how to use the bean Name Url Handler Mapping using the Spring WEB MVC framework. The Beannameurlhandlermapping class is the default handler mapping class that map
IOC refers to the inversion of control, the creation of objects, initialization, destruction and other work to the spring container. The spring container controls the life cycle of the object.Spring Object Initialization Bean timing:By default, as long as a bean is configured in the
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 B
should be Type changed to Schema Location,key to Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
4. Assembling beans (first lecture)
one, to accommodate your bean
Bean Factory : The simplest container that provides the foundation for dependency injection support. Create various types of beans.
Application Context : Built on the
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
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 inheritance of beans in Spring is very different from the inheritance in Java, which is the continuation of the arguments between the instance and the instance, which is the general to the special refinement, the former is the relationship between the object and the object, the latter is the relationship be
Problem:When injecting a multi-instance bean into a singleton bean, it is not getting to that multi-sample object, because, when the singleton is initialized, it is initialized directly, and this multi-instance bean is always getting the first initialized bean.Configuration file:
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:aop= "HTTP:
Turn from: http://www.ibm.com/developerworks/cn/webservices/ws-springjava/
Overview
As we all know, the Spring framework is a driving factor in the control reversal (IOC) or Dependency injection (DI) pattern, which is implemented through a container based configuration. In the past, Spring allows developers to use xml-based configurations to manage bean dependenc
] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX exposure on startup2018-09-08 16:25: 55.539 INFO 2584---[main] com.gyc.GycApplication:Started gycapplication in 1.922 seconds (JVM running for 3.01) 2018-09-08 16:25:55.544 INFO 2584---[Thread-6] s.c.a.annotationconfigapplicationcontext: Closing org.spring[emailprotected]7b227d8d:startup Date [Sat Sep 16:25:54 CST 2018]; Root of context hierarchy2018-09-08 16:25:55.548 INFO 2584---[Thread-6] o.s.j.e.a.annotationmbeanexporter
Declare a bean as an abstract bean by specifying abstract= "true", which can be inherited;
xml version="1.0" encoding="GBK"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring
Method injection is rarely used in spring, where the main application is that a protected abstract method may be defined in the object, and the container may implement it at runtime to return the object that is queried by the container.
One of the best uses of method injection is to handle situations where a single state, stateless object needs to invoke a non-state, stateful, or non-thread-safe object.
When you first contacted
In traditional Java applications, bean lifecycle is very simple. Java keyword new is used to instantiate Bean (maybe non-serialized ). This is enough. On the contrary, bean lifecycle is more detailed in spring containers. Understanding the lifecycle of spring
1. Spring Factory classThe Spring factory class we used in the demo in front of us is classpathxmlapplicationcontext, and we can see that he has a brother class Filesystemapplicationcontext, This class is the same as loading a configuration file under a non-classpath path.From the inheritance graph, you can see the applicationcontext that we often see, which is the factory class interface introduced in the
Stateful session Bean: each user has its own unique instance, during the lifetime of the user, the bean maintains the user's information, namely "stateful"; Once the user dies (the end of the call or the end of the instance), the bean's lifetime ends. That is, each user will initially get an initial bean.Stateless session Bean:bean Once instantiated, they are added to the session pool and can be shared by i
Scope of Bean in spring:In the spring container, the scope of the bean is by default a single mode, Singleton, and the single case pattern can be accessed concurrently by multiple threads, if
We want to change the scope of the bean and change it to multiple patterns, that is, each time you get the same
1.spring MVC returns JSON data and only needs to return a Java Bean object, as long as the Java Bean Object implements serialization Serializeable2.@RequestMapping (value = {"/actor_details"}, Method ={requestmethod.post}) @ResponseBody Publicresultobject actordetails (@RequestBody actordetailsrequest req) {logger.debug ("View {} host information", Req.getaid ())
Setuserdao (@Qualifier("Userdao") Userdao Userdao) {
this. Userdao = Userdao;
}
In this way, spring will find the bean with ID userserviceimpl and Userdao to assemble.2). Userdao instances may not existJava code
@Autowired (required = false)
Public Iuserservice UserService;
@Autowired can comment on member variables, methods, and constructors, while @Qualif
(1) Each bean should provide a unique name or ID and a fully qualified class name for the IOC container to instantiate it. You can specify a
You can also declare it in the In fact, the preferred method for marking beans is: through the standard xml id attribute, if your text editor is XML aware, you can verify the uniqueness of each bean during design. This is concise. Starting from
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.