课程
/后端开发
/Java
/Spring入门篇
这是什么错误?代码都是按照老师写的
2017-07-24
源自:Spring入门篇 4-2
正在回答
如果自行撰写了构造函数,编译程序就不会自动建立默认构造函数,所以会初始化失败。在private InjectionDAO injectionDAO上 或者 setter上@Autowired的话,而且撰写的带参构造函数没有注释掉,前两者就没有默认构造函数来调用形成实例对象了,所以报错里头会有说no default constructor 还有 initialization失败
复制粘贴就是容易错。。。
@Autowired
private InjectionDAO injectionDAO;
//设置注入
public void setInjectionDAO(InjectionDAO injectionDAO) {
this.injectionDAO = injectionDAO;
}
//构造器注入
public InjectionServiceImpl(InjectionDAO injectionDAO){
this.injectionDAO=injectionDAO;
三个共存就会报错,除非注解在set或构造函数上,不懂得为什么?
举报
为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础
1 回答Error creating bean with name 'aspectBiz'
7 回答异常信息提示 Error creating bean with name 'aspectdome' defined in class path resource [springaop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
2 回答Error creating bean with name 'moocAspect' defined in class path resource ,这个是什么情况?
1 回答Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aspectJ' defined in class path resource [ApplicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is
1 回答Error creating bean with name 'serviceImp' defined in URL [file:/E:/workspace/SpringIOC/WebRoot/WEB-INF/classes/injection.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'da