dz̸Springѧϰ֮request,sessionÓëglobalSession×÷ÓÃÓò
ÓëwebÈÝÆ÷ÓйصÄ×÷ÓÃÓò£¬Ê×ÏÈÒªÔÚWebÈÝÆ÷Àï½øÐÐһЩÅäÖᣠ<web-app> ... <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> ... </web-app> Request×÷ÓÃÓò ¿¼ÂÇÏÂÃæbean¶¨Ò壺 <bean id="loginAction" class="com.foo.LoginAction" scope="request"/> Õë¶Ôÿ´ÎHTTPÇëÇó£¬SpringÈÝÆ÷»á¸ù¾ÝloginAction bean¶¨Òå´´½¨Ò»¸öȫеÄLoginAction beanʵÀý£¬ ÇÒ¸ÃloginAction beanʵÀý½öÔÚµ±Ç°HTTP requestÄÚÓÐЧ£¬Òò´Ë¿ÉÒÔ¸ù¾ÝÐèÒª·ÅÐĵĸü¸ÄËù½¨ÊµÀýµÄÄÚ²¿×´Ì¬£¬ ¶øÆäËûÇëÇóÖиù¾ÝloginAction bean¶¨Òå´´½¨µÄʵÀý£¬½«²»»á¿´µ½ÕâÐ©ÌØ¶¨ÓÚij¸öÇëÇóµÄ״̬±ä»¯¡£ µ±´¦ÀíÇëÇó½áÊø£¬request×÷ÓÃÓòµÄbeanʵÀý½«±»Ïú»Ù¡£ Session×÷ÓÃÓò ¿¼ÂÇÏÂÃæbean¶¨Ò壺 <bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/> Õë¶Ôij¸öHTTP Session£¬SpringÈÝÆ÷»á¸ù¾ÝuserPreferences bean¶¨Òå´´½¨Ò»¸öȫеÄuserPreferences beanʵÀý£¬ ÇÒ¸ÃuserPreferences bean½öÔÚµ±Ç°HTTP SessionÄÚÓÐЧ¡£ Óërequest×÷ÓÃÓòÒ»Ñù£¬Äã¿ÉÒÔ¸ù¾ÝÐèÒª·ÅÐĵĸü¸ÄËù´´½¨ÊµÀýµÄÄÚ²¿×´Ì¬£¬¶ø±ðµÄHTTP SessionÖиù¾ÝuserPreferences´´½¨µÄʵÀý£¬ ½«²»»á¿´µ½ÕâÐ©ÌØ¶¨ÓÚij¸öHTTP SessionµÄ״̬±ä»¯¡£ µ±HTTP Session×îÖÕ±»·ÏÆúµÄʱºò£¬ÔÚ¸ÃHTTP Session×÷ÓÃÓòÄÚµÄbeanÒ²»á±»·ÏÆúµô¡£ global session×÷ÓÃÓò ¿¼ÂÇÏÂÃæbean¶¨Ò壺 <bean id="userPreferences" class="com.foo.UserPreferences" scope="globalSession"/> global session×÷ÓÃÓòÀàËÆÓÚ±ê×¼µÄHTTP Session×÷ÓÃÓò£¬²»¹ýËü½ö½öÔÚ»ùÓÚportletµÄwebÓ¦ÓÃÖвÅÓÐÒâÒå¡£Portlet¹æ·¶¶¨ÒåÁËÈ«¾ÖSessionµÄ¸ÅÄËü±»ËùÓй¹³Éij¸öportlet webÓ¦Óõĸ÷ÖÖ²»Í¬µÄportletËù¹²Ïí¡£ÔÚglobal session×÷ÓÃÓòÖж¨ÒåµÄbean±»ÏÞ¶¨ÓÚÈ«¾Öportlet SessionµÄÉúÃüÖÜÆÚ·¶Î§ÄÚ¡£ Çë×¢Ò⣬¼ÙÈçÄãÔÚ±àдһ¸ö±ê×¼µÄ»ùÓÚServletµÄwebÓ¦Ó㬲¢ÇÒ¶¨ÒåÁËÒ»¸ö»ò¶à¸ö¾ßÓÐglobal session×÷ÓÃÓòµÄbean£¬ÏµÍ³»áʹÓñê×¼µÄHTTP Session×÷ÓÃÓò£¬²¢ÇÒ²»»áÒýÆðÈκδíÎó¡£ ×÷ÓÃÓòÒÀÀµÎÊÌâ If you want to inject (for example) an HTTP request scoped bean into another bean of a longer-lived scope,you may choose to inject an AOP proxy in place of the scoped bean. That is,you need to inject a proxy object that exposes the same public interface as the scoped object but that can also retrieve the real target object from the relevant scope (such as an HTTP request) and delegate method calls onto the real object. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- an HTTP Session-scoped bean exposed as a proxy --> <bean id="userPreferences" class="com.foo.UserPreferences" scope="session"> <!-- instructs the container to proxy the surrounding bean --> <aop:scoped-proxy/> </bean> <!-- a singleton-scoped bean injected with a proxy to the above bean --> <bean id="userService" class="com.foo.SimpleUserService"> <!-- a reference to the proxied userPreferences bean --> <property name="userPreferences" ref="userPreferences"/> </bean> </beans> ×ܽá ÒÔÉϾÍÊDZ¾ÎĹØÓÚSpringѧϰ֮request,sessionÓëglobalSession×÷ÓÃÓòµÄÈ«²¿ÄÚÈÝ£¬Ï£Íû¶Ô´ó¼ÒÓÐËù°ïÖú¡£¸ü¶àÄÚÈÝÇë²Î¿¼£ºSpring spel±í´ïʽʹÓ÷½·¨Ê¾Àý¡¢JavaÖ®Spring×¢½âÅäÖÃbeanʵÀý´úÂë½âÎö¡¢javaÖÐjavaBeanÓëBeanµÄÉîÈëÀí½âÒÔ¼°±¾Õ¾ÆäËûÀ¸Ä¿£¬¸Ðл´ó¼Ò¶Ô±¾Õ¾µÄÖ§³Ö£¡ £¨±à¼£ºÀî´óͬ£© ¡¾ÉùÃ÷¡¿±¾Õ¾ÄÚÈݾùÀ´×ÔÍøÂ磬ÆäÏà¹ØÑÔÂÛ½ö´ú±í×÷Õ߸öÈ˹۵㣬²»´ú±í±¾Õ¾Á¢³¡¡£ÈôÎÞÒâÇÖ·¸µ½ÄúµÄȨÀû£¬Ç뼰ʱÓëÁªÏµÕ¾³¤É¾³ýÏà¹ØÄÚÈÝ! |
- java ¨C µ±ÎÒÃǸÄΪ×Ö½ÚʱΪʲôµ±127 * 2ʱ½á¹ûÊÇ-2£¿
- Java²¢·¢±à³Ì£ºCountDownLatchÓëCyclicBarrierºÍSemaphoreµÄ
- java ¨C ³Ö¾ÃÐÔ´íÎóÏûÏ¢£ºÎª²éÕÒ²Ù×÷´íÎóµØÌṩÁË¿ÕPKµÄʵÀý
- java ¨C ×î¼Ñʵ¼ù ¨C ÔÚµ¥Ôª²âÊÔÖÐÉèÖò»´øsetterµÄ×Ö¶Î
- How Do Annotations Work in Java?--ת
- SpringBootÏîÄ¿´ò°üÈý·½JARµÄʾÀý´úÂë
- java ¨C ΪʲôÕâ¸ö·½·¨µ÷ÓÃʧ°Ü£¿ (·ºÐͺÍͨÅä·û)
- SpringWeb <form:radiobutton>±êÇ©£º¶¨Òå±íµ¥µÄµ¥Ñ¡°´Å¥×é
- java ¨C ΪʲôÔÚËĺ˻úÆ÷ÉÏʹÓöà¸öÏß³Ìʱ,´Ë´úÂëûÓп´µ½
- HibernateÖ®openSessionÓëgetCurrentSessionµÄÇø±ð
- java ¨C ÈçºÎ»ñÈ¡JlistÏîĿ֮¼äµÄ×Ô¶¨Òå¿Õ¼ä£¿
- luogu P4198 Â¥·¿Öؽ¨
- java ¨C Long a = Long.valueOf(1)»òLong a = 1L
- ÈçºÎÔÚjavaÖеÄÏÖÓÐPDFÖÐÌí¼Ó¿Õ°×Ò³£¿
- JVMÄÚ´æ½á¹¹
- java ¨C ¾ßÓÐMockito.when()ºÍ·ºÐÍÀàÐÍÍÆ¶ÏµÄÆæ¹Ö
- JavaWebʵÏÖͬһÕʺÅͬһʱ¼äÖ»ÄÜÒ»¸öµØµãµÇ½£¨
- java ¨C ÈçºÎ¼ÆËãarraylistÖÐÌØ¶¨ÀàµÄʵÀýÊý£¿
- ʹÓÃJava½øÐÐÒôƵ´¦Àí
- spring cloudÈçºÎÐÞ¸´zuul¿çÓòÅäÖÃÒì³£µÄÎÊÌâ