2013-12-09 66 views
0

我正在开发一个使用Spring注入的系统。在某个点上,屏幕上会显示一条警告,该警告使用一个名为Spring Controller的WarningHelper类的属性显示。以下是总结代码:春季控制器保持旧值

@Controller 
@Scope(WebApplicationContext.SCOPE_SESSION) 
public class WarningHelper implements Serializable { 
    //Bunch of attributes 
    private String warningText; 

    //Bunch of other methods 

    private String configureWarning(Integer caller, Outcome outcome, WarningReturn warningReturn, GlobalWebUser user) { 
      //business logic 

    if (hasWarning()) { 
     setWarningText(warningReturn.getWarningText()); 
    } 

    return redirect; 
} 
} 

该部分完美地工作。稍后,xhtml页面会使用另一个控制器显示此警告,其中第一个控制器将注入此警告。以下是第二个控制器的编辑代码:

@Controller 
@Scope(WebApplicationContext.SCOPE_APPLICATION) 
public class CustomUrlController { 

    //Bunch of other attributes 
@Inject 
private WarningHelper warningHelper;  

    //Bunch of methods 
    public String getAllMessages() { 
     String completeMessage = ""; 
     //business logic creating the message 
     completeMessage += warningHelper.getWarningText(); 

     return complete Message 
    } 
} 

这一切都工作得很好,第一次。问题是,如果我尝试输入另一个具有不同消息的配置文件,则仍会显示第一个配置文件。请注意,此更改过程不涉及其他登录,因此会话仍然相同。我试图绕过范围,但无济于事。

回答

1

更改在@Scope(WebApplicationContext.SCOPE_SESSION)@Scope(WebApplicationContext.SCOPE_REQUEST)WarningHelperCustomUrlController类。这将为每个请求实例化CustomUrlControllerwarningHelper

+0

似乎它的工作。我会再测试一下,但初步测试很好!谢谢! –

+0

欢迎您:) – Keerthivasan