关于spring2.5的@Scoped

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

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
原文地址:https://www.cnblogs.com/huqingyu/p/1745524.html