2
我正在使用Spring MVC框架。在下面的代码片段中,当我构建它时(即使用@Autowired
或ApplicationContextAware
接口),Spring可能会将bean注入请求参数MyRequestClass
?我需要这个请求对象来访问我的单例Spring bean中的一个,并且不必为此创建一个实现单例的ApplicationContextAware
。@构建为MVC方法参数的bean中的自动属性
到目前为止,我只是试图用任一方法访问beanaroo属性的NullPointerExceptions。
@RequestMapping("/**")
@Controller
public class MyController {
@RequestMapping(value = "/mymethod", method = RequestMethod.POST)
public ModelAndView myMethod(@RequestBody MyRequestClass request,
ModelMap modelMap,
HttpServletResponse response) {
...
}
}
例如,
public class MyRequestClass {
@Autowired
private MyInjectedBean beanaroo;
}
我也试过在我的应用程序上下文文件中定义该类的原型豆,但它并没有任何效力,要么。
好点...这是一个足够简单的解决方案。不知道为什么这首先没有发生在我身上!感谢Bozho – 2011-05-09 13:48:52