それ。そのような場合のベストプラクティスは何ですか?リクエストスコープのサービスは問題ありませんか?CGLIBプロキシ(最終クラス)
@Configuration
public class CityFactory{
@Bean(name = {"currentUserId")
@Scope(value = WebApplicationContext.SCOPE_REQUEST,proxyMode = ScopedProxyMode.TARGET_CLASS)
@Autowired
public Integer getUserId(HttpServletRequest request) {
return UserUtil.getCurrentUserId(request.getServerName());
}
}
@RequestMapping("/demo")
@Controller
public class DemoController {
@Autowired
Ingeter userId;
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
public ModelAndView helloWorld(@PathVariable("name") String name, Model model) {
Map<String, Object> myModel = new HashMap<String, Object>();
model.addAttribute("user", userId);
return new ModelAndView("v3/test", "m", model);
}
}
を使用することができますか? –
@Sean:これはCGLIBの働きだからです。 – skaffman
@skaffmanコントローラやIDクラスのサブクラス化を理解できますが、なぜIntegerですか? –