繁体   English   中英

春豆自动装配不起作用

[英]Spring bean autowiring not work

有人可以帮助解决这个问题吗? 我将Spring与zk集成在一起,并且自动连线的服务bean在控制器中始终为null。

package com.test.MVC.controller;

@Controller
@Scope("prototype")
public class MainController extends SelectorComposer<Component>{
  private MainService mainService;

  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);
    List<Map<String, Object>> list = mainService.query(null);//the mainService is always null here
  }
  @Autowired
  public void setMainService(MainService mainService) {
    this.mainService = mainService;
  }
}

package com.test.MVC.service.impl;

@Service("mainService")
public class MainServiceImpl implements MainService {//MainService: surface

  private JdbcTemplate jdbcTemplate;

  public List<Map<String, Object>> query(Integer number){...}//please ignore the content

  @Autowired
  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {//inject bean
    this.jdbcTemplate = jdbcTemplate;
  }
}

我确实在xml文件中添加了以下设置

<context:component-scan base-package="com.test.MVC" />
<context:annotation-config/>

更新:我只是发现控制器中的设置器永远不会被调用。

这是因为您在ZK容器中而不是在弹簧容器中进行搜索。

Zk为此具有特定的variabeleResolver。
请阅读: https : //www.zkoss.org/wiki/ZK_Developer's_Reference/MVC/Controller/Wire_Variables

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM