计数.java:
@Component
@Scope(value = "session",proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Count {
Integer i;
public Count() {
this.i = 0;
}
控制器:
@Controller
public class GreetingController {
@Autowired private Count count;
@RequestMapping("/greeting")
public String greetingForm(Model model) {
if(count.i == null) i == 0;
else i++;
model.addAttribute("count",String.valueOf(count.i));
return "greeting";
}
}
但是每次我运行这个控制器(/greeting)时,即使我关闭浏览器,它总是会增加 i,那么我如何在单例控制器中使用这个 Session Scoped Component?