Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring控制器保留旧值_Java_Spring_Controller_Code Injection - Fatal编程技术网

Java Spring控制器保留旧值

Java Spring控制器保留旧值,java,spring,controller,code-injection,Java,Spring,Controller,Code Injection,我正在开发一个使用弹簧注入的系统。在某个时间点,屏幕上会显示一条警告,该警告使用WarningHelper类(一个Spring控制器)上的属性显示。以下是代码摘要: @Controller @Scope(WebApplicationContext.SCOPE_SESSION) public class WarningHelper implements Serializable { //Bunch of attributes private String warningText

我正在开发一个使用弹簧注入的系统。在某个时间点,屏幕上会显示一条警告,该警告使用WarningHelper类(一个Spring控制器)上的属性显示。以下是代码摘要:

@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
    }   
}

这一切在第一次的时候都很好。问题是,如果我尝试输入另一个具有不同消息的配置文件,第一个配置文件仍会显示。请注意,此更改过程不涉及其他登录,因此会话仍然相同。我试过玩弄这个作用域,但没有用。

警告帮助自定义URLController类中将
@scope(WebApplicationContext.scope\u会话)
更改为
@scope(WebApplicationContext.scope\u请求)
。这将为每个请求实例化
CustomUrlController
warninghelp

似乎有效。我会再测试一些,但初步测试很好!谢谢