我控制器具有自動裝配Autowired場「resultados」Spring MVC。豆NULL值
@Controller
public class MyController {
@Autowired
private CursoDelegate cursoDelegado;
@Autowired
private List<Articulo> resultados;
@RequestMapping(value = "consultarArticulos.html")
public ModelAndView consultarArticulos() {
ModelAndView modelAndView= new ModelAndView("consultarArticulos");
modelAndView.addObject("resultados", resultados);
return modelAndView;
}
而且我定義配置類的豆。 「cursoDelegado.consultarArticulos()」方法返回三個元素的集合,但bean始終爲空。還有其他類但這裏不需要
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.myapp")
public class MyConfig extends WebMvcConfigurerAdapter {
@Bean
public List<Articulo> resultados()
{
try {
return cursoDelegado.consultarArticulos();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
}
對不起,我沒有粘貼所有代碼,但應用程序運行並聲明瞭所有的bean。該problema是 「resultados」
我更改代碼:
,現在其確定。接口列表有任何問題,但我不知道原因。如果任何人都可以解釋我的problema :)
它可能會混淆實際問題存在的方法'MyController.consultarArticulos'和'CursoDelegate.consultarArticulos'。發佈'CursoDelegate' – Reimeus