2011-05-05 90 views
0

您好我有SOAP Web服務(Java中,春天,Tomcat)的春豆範圍

在我的web.xml文件中,我有一個參考MessageDispatcherServlet,這是我servlet.xml文件看起來像:

<?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:sws="http://www.springframework.org/schema/web-services" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/web-services 
http://www.springframework.org/schema/web-services/web-services-2.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 

<description></description> 

<bean id="payloadMapping" 

class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"> 
    <property name="defaultEndpoint" ref="inferenceEndPoint" /> 
    <property name="interceptors"> 
     <list> 
      <ref local="validatingInterceptor" /> 
      <ref local="payLoadInterceptor" /> 
     </list> 
    </property> 
</bean> 
. 
. 
. 

現在我想使用Spring的請求範圍豆,什麼是創建這個bean的步驟?我必須創建多少個不同的類,以及如何修改我的xml文件。對於使用會話範圍,我在某處讀到:

「爲了使用會話作用域,您必須使用Web感知的Spring應用程序上下文,例如XmlWebApplicationContext。否則,範圍代理無法引用當前會話「

我是否也需要類似這樣的東西來使用請求範圍?

感謝

回答

1

你已經有dispatcher-servlet.xml(這是默認的名稱),讓您擁有一個WebApplicationContext。現在您只需要定義<bean scope="request"scope="session"

如果使用註釋,則可以使用@Scope("request")。另請注意,請求和會話範圍的bean比單例範圍的bean更少使用。

+0

謝謝,我需要創建多少班?在此鏈接中,它描述瞭如何創建會話作用域,並創建了4個類:控制器,服務接口,服務實現和模型類。必須創建這些類,並且可以檢查xml文件是否與更改範圍名稱相同? http://wheelersoftware.com/articles/spring-session-scoped-beans.html – Spring 2011-05-05 07:48:15

+0

好吧,那完全取決於你想用它做什麼。會話bean只需要一個類。其他3個用於所有層的全部功能。 – Bozho 2011-05-05 08:04:05

+0

並引用鏈接中的示例xml是否正確?:關於代理事物的困惑 <! - 這需要CGLIB - > Spring 2011-05-05 08:19:22