浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

网上很多都讲不清楚。得了,还是看官网吧:

http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes

 

新加了@Scoped,里边可以选session、request等,不过,需要在web.xml中再配置一下:

<web-app>
...
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
  <filter> 
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

...
</web-app>

然后再给Action类加上Annotation:
@Service
@Scoped(Scope.SESSION)
@InterceptorRef("defaultStack")
public class ProxyAction extends BaseActionSupport implements ServletRequestAware
{
...
}

注意这里的import:
import com.opensymphony.xwork2.inject.Scope;
import com.opensymphony.xwork2.inject.Scoped;

Scope并非annotation!要注意,因为还有一个annotation名字就叫scope
posted on 2010-05-27 16:30  浙林龙哥  阅读(350)  评论(0编辑  收藏  举报