为什么这样错了?

来源:4-2 Spring Bean装配之Autowired注解说明-1

涅槃ing

2016-01-24 20:23

@Autowired

private InjectionDAO injectionDAO;

//@Autowired

public InjectionServiceImpl(InjectionDAO injectionDAO) {

this.injectionDAO = injectionDAO;

}

//@Autowired 

public void setInjectionDAO(InjectionDAO injectionDAO) {

this.injectionDAO = injectionDAO;

}


写回答 关注

6回答

  • 慕粉1473922411
    2019-01-16 23:01:25

    题主,解决了吗

  • 那一年故乡
    2017-08-21 16:43:21

    解决了吗,我也遇到同样的问题了


  • 饺子不要馅
    2017-06-14 23:16:07

    应该是你的配置文件不对,没能识别@autowired注解

  • 按照自己的节奏前行
    2016-05-22 21:15:33

    No default constructor found,你自己写了一个构造器,

    public InjectionServiceImpl(InjectionDAO injectionDAO) {

    this.injectionDAO = injectionDAO;

    }

    并且将注解注释掉了,java你自己谢了构造器他就不会生成默认的构造器,所以找不到了

  • rookie2maven
    2016-03-11 21:41:07
    @Autowired是对成员变量和函数,构造方法进行标注,完成自动装配,被你注释掉了


  • 涅槃ing
    2016-01-24 20:26:16

    提示:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'injectionServiceImpl' defined in file [C:\Users\***\workspaceEE\springtest\bin\beanannotation\injection\service\InjectionServiceImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [beanannotation.injection.service.InjectionServiceImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: beanannotation.injection.service.InjectionServiceImpl.<init>()


Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268785 学习 · 963 问题

查看课程

相似问题