1
1楼 aninfeel 2007-06-06
我只是直接在web.xml里加了个linster: <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
然后在WEB-INF下加了个spring的applicationContext.xml,在这个文件里定义好的been,在xwork.xml的action里的class可以直接使用它的id。但问题是applicationContext里的bean只可以使用singleton和prototype scope,我想问的是怎样才能使用request scope呢?虽然prototype好像可以满足需要。 2楼 deafwolf 2007-06-06
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> 去看spring framework开发参考手册 3楼 movingboy 2007-06-07
1.web.xml的定义必须符合Servlet 2.4标准(当然你的web服务器也要支持这个标准),例如:
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Detailed configuration omitted -->
</web-app>
2.在applicationContext.xml中增加支持其它scope的listener(楼上已经提到了,略) 3.将bean配置成需要的scope,例如: <bean id="idOfBean" class="class.of.bean" scope="request"> <!-- Other configuration omitted --> </bean> 重复一下楼上的建议:建议仔细读读Spring的手册,这些内容很容易找到的 4楼 FGhost 2007-10-18
应该还需要一个代理
<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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="requestScope" scope="request">
<aop:scoped-proxy/>
</bean>
</beans>
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源
| |||||