title: Can I access Spring session-scoped beans from application-scoped beans? How?
body: <p>I'm trying to make this 2-player web game application using Spring MVC. I have session-scoped beans <code>Player</code> and application-scoped bean <code>GameList</code>, which creates and stores <code>Game</code> instances and passes them to <code>Players</code>. On player creates a game and gets its ID from <code>GameList</code> and other player sends ID to <code>GameList</code> and gets <code>Game</code> instance.
  The <code>Game</code> instance has its players as attributes. Problem is that each player sees only himself instead of the other one.</p>
  
  <p>Example of what each player sees: </p>
  
  <ol>
  <li>First player (Alice) creates a game: <code>Creator: Alice, Joiner: Empty</code> </li>
  <li>Second player (Bob) joins the game: <code>Creator: Bob, Joiner: Bob</code></li>
  <li>First player refreshes her browser <code>Creator: Alice, Joiner: Alice</code></li>
  </ol>
  
  <p>What I want them to see is <code>Creator: Alice, Joiner: Bob</code>. Easy way to achieve this is saving information about players instead of references to players, but the game object needs to call methods on its player objects, so this is not a solution.</p>
  
  <p>I think it's because of <code>aop:scoped-proxy</code> of session-scoped Player bean. If I understand this, the Game object has reference to proxy, which refers to Player object of current session. Can Game instance save/access the other Player objects somehow?</p>
  
  <p>beans in <strong>dispatcher-servlet.xml:</strong></p>
  
  <pre><code>&lt;bean id="userDao" class="authorization.UserDaoFakeImpl"  /&gt;
  &lt;bean id="gameList" class="model.GameList" /&gt;
  &lt;bean name="/init/*" class="controller.InitController" &gt;
       &lt;property name="gameList" ref="gameList" /&gt;
       &lt;property name="game" ref="game" /&gt;
       &lt;property name="player" ref="player" /&gt;
  &lt;/bean&gt;
  &lt;bean id="game" class="model.GameContainer" scope="session"&gt;
        &lt;aop:scoped-proxy/&gt;
  &lt;/bean&gt;
  &lt;bean id="player" class="beans.Player" scope="session"&gt;
        &lt;aop:scoped-proxy/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>methods in <strong>controller.InitController</strong></p>
  
  <pre><code>private GameList gameList;
  private GameContainer game;
  private Player player;
  public ModelAndView create(HttpServletRequest request,
          HttpServletResponse response) throws Exception {        
      game.setGame(gameList.create(player));        
      return new ModelAndView("redirect:game");
  }
  public ModelAndView join(HttpServletRequest request,
          HttpServletResponse response, GameId gameId) throws Exception {
      game.setGame(gameList.join(player, gameId.getId()));       
      return new ModelAndView("redirect:game");
  }
  </code></pre>
  
  <p>called methods in <strong>model.gameList</strong></p>
  
  <pre><code>public Game create(Player creator) {        
      Integer code = generateCode();        
      Game game = new Game(creator, code);
      games.put(code, game);
      return game;
  }
  public Game join(Player joiner, Integer code) {
      Game game = games.get(code);
      if (game!=null) {
          game.setJoiner(joiner);           
      }
      return game;
  }
  </code></pre>