Say I have the following class...
@Controller
public class WebController {
@Autowired PersonService personService;
@RequestMapping(value = "/get", method = RequestMethod.GET)
@ResponseBody
@Scope("session")
public List<Player> getPerson(String personName) {
return playerService.getByName(personName);
}
}
Now this invokes the following service...
@Service("playerService")
public class PlayerServiceImpl implements PlayerService {
private List<Player> players;
@Override
@Transactional
public List<Player> getByName(final String name) {
if (players == null) {
players = getAll();
}
return getValidPlayers(name);
}
If I initially start my application, players is null, correctly, then when in the same session, I invoke this method again with a new value, players is no longer null, as you would expect. However, no new thread appears to be being created, if I open a new browser window (therefore creating a new session) and invoke this method, it still has the values from the previous session.
Why is @Scope("session") not creating a new thread in the thread pool?
I've specified <context:component-scan base-package="com." />
in my servlet-context as expected, everything works fine apart from the service methods are all acting as singletons rather than creating a new thread per session like say a Java EE container.
If players was marked as static I'd understand.
I've also tried marking my controller as @Scope("session")
(as shown below) but this appears to have no impact either. What's the best way to make my Spring app create a new thread for a new session?
@Controller
@Scope("session")
public class PlayerController {