嗨,我有一个肥皂网络服务(java,spring,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,创建这个bean的步骤是什么?我必须创建多少个不同的类以及如何修改我的 xml 文件。对于使用 session 范围,我在某处读到:
“为了使用 session 作用域,您必须使用 Web 感知的 Spring 应用程序上下文,例如 XmlWebApplicationContext。否则作用域代理无法引用当前 session ”
我是否也需要类似的东西来使用请求范围?
谢谢
最佳答案
您已经有dispatcher-servlet.xml
(这是默认名称)所以你有一个 WebApplicationContext
。现在你只需要定义 <bean scope="request"
或scope="session"
如果使用注释,可以使用@Scope("request")
。另请注意,请求和 session 范围的 Bean 比单例范围的 Bean 更少使用。
关于java - Spring bean 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5894127/