Spring MVC中CGLib Proxy for Integer(Final class)
我需要这样的用法:
对于每个请求,我想将userId注入DemoController但是由于是一个没有空构造函数的最终类,我无法注入它。在这种情况下,最佳做法是什么?请求范围的服务很好吗?
@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);
}
}
没有找到相关结果
已邀请:
2 个回复
坛沤疲撑拆
的显式类,它又包含一个整数。 CGLIB的代理不仅可以更好地发挥作用,还可以澄清您的设计。
疼嘶桐