首页 新闻 会员 周边

Spring MVC注解扫描问题

0
悬赏园豆:200 [已关闭问题] 关闭于 2014-08-20 09:24

在项目中使用Spring MVC,分别用到了@Controller @Service @Repository,例如:

@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/greet")
    public String greetWorld(
            @RequestParam(value = "name", required = false, defaultValue = "World") String name, Model model) {
        String showCase = demoService.demoShow();
        model.addAttribute("msg", "Greet " + name + " " + showCase);

        return "demo/hello";
    }
@Service
public class DemoServiceImpl implements DemoService {

    @Autowired
    private DemoManager demoManager;

    public String demoShow() {
        return demoManager.showCase();
    }
}
@Repository
public class DemoManagerImpl implements DemoManager {

    @Autowired
    private DemoDao demoDao;

    public String showCase() {
        return demoDao.showCase();
    }
}

然后我想在Servlet上下文初始化的过程中获取所有的@Service,代码如下:

public class DemoListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent servletContextEvent) {
        try {
            AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
            ctx.scan(new String[] { "demo.service","demo.manager","demo.dao" });
            ctx.refresh();
            Map<String, Object> services = ctx.getBeansWithAnnotation(Job.class);

...

当执行到ctx.refresh()的时候就出现了错误,一直没有找到问题,非常感谢!

treerain的主页 treerain | 初学一级 | 园豆:16
提问于:2014-08-19 17:15
< >
分享
所有回答(1)
0

没用过spring ,不过有更详细一点的错误信息么?

幻天芒 | 园豆:37175 (高人七级) | 2014-08-20 00:05

多谢天芒,已自己解决

支持(0) 反对(0) treerain | 园豆:16 (初学一级) | 2014-08-20 09:23

@treerain: good!

支持(0) 反对(0) 幻天芒 | 园豆:37175 (高人七级) | 2014-08-20 09:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册