0

我想在spring MVC中设置一个应用程序变量我可以这样做吗

  @Scope("globalSession")
  public class ApplicationVariable{

    public static appVar;

  }

这个变量在整个应用程序中都可用吗?或者有没有其他更好的方法来做到这一点?

4

1 回答 1

2

默认情况下,spring bean 是单例的,因此它将始终在全局范围内可用。在上面的示例中,您应该将 ApplicationVariable bean 保留为单例范围,将变量保留为实例而不是静态,并在需要变量时注入 bean。

于 2012-09-26T13:42:12.943 回答