상세 컨텐츠

본문 제목

Spring+struts2 환경에서 config에 action scope 정의 방법

Programming/Spring Framework

by otamot 2009. 10. 21. 15:00

본문

  Spring + Struts2 를 통합해서 사용할 때 다른 bean들은 singleton으로 default 값을 정의해도 되나 action은 singleton으로 정의 하면 문제가 발생할 수 있다.
  동시 사용자들이 사용할 경우  action 객체를 공유하게 되면 수행 결과가 엉뚱하게 나타날 수도 있는 문제가 발생한다.

<!-- action을 정의 할 때 scope를 default(=singleton)값으로 하지 말고 prototype로 정의 해야 함. -->
    <bean id="userAction" class="org.ssi.action.UserAction"  scope="prototype"
        p:userService-ref="userService"
    />

위에서  scope 속성을 정의 했는데  default 값은 'singleton'이다. 이것을 prototype으로 정의하면 action수행 할 때마다 action 객체가 생성된다.

관련글 더보기