Announcement Announcement Module
No announcement yet.
Annotated bean scope for SWF Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annotated bean scope for SWF


    I have a little question. In my web application, I have a simple annotated Spring bean, for example:

    public class MyBean implements Serializable {
        private String data;
        public String getData() {
            return data;
        public void setData(String data) {
   = data;
    And I want to use that bean in one of my flows so i declare it in my flow xml definition file like:

    <var name="myBean" class="my.package.MyBean" />
    So far, so good, right?

    My question is: When the IoC container instantiates the MyBean object it uses the singleton scope by default, correct? So, how would I define MyBean to have a SWF scope? Or by defining it in the xml it gets refactored?

    Thank you very much in advance...

  • #2
    I believe there's a way to annotate your bean to give it a SWF-specific scope.

    However...I like to define which scope I'm using explicity in my flow definition so it's easy to track and look up, and easy to shift between scopes if needed.

    In my case, I defined these kinds of beans in a beans xml file as "prototype" scope, with names with "new" as the prefix in the id. Then I use set actions in the appropriate places in my flow definition (top of the flow, within a state, whatever) to get a prototype instance of the bean and explicitly place it into scope using any name I like.

    You should be able to do the same with annotations fairly easily, if you want this approach. Otherwise, just scope your bean appropriately.