我从Spring reference 3.0开始学习spring,我想尝试如何实例化内部bean:
这是我的代码:
package com.springexample;
public class ExampleBean {
private String samplePropertyExampleBean;
public void setSamplePropertyExampleBean(String samplePropertyExampleBean) {
this.samplePropertyExampleBean = samplePropertyExampleBean;
}
public String getSamplePropertyExampleBean() {
return samplePropertyExampleBean;
}
class InnerBean{
private String sampleProperty;
public void setSampleProperty(String sampleProperty) {
this.sampleProperty = sampleProperty;
}
public String getSampleProperty() {
return sampleProperty;
}
}
}
我的配置文件是:
当我试图检索bean InnerBean时,我收到以下错误:
线程“main”中的异常org.springframework.beans.factory.BeanCreationException:创建类路径资源[spring-config.xml]中定义名为’InnerBean’的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[com.springexample.ExampleBean $InnerBean]:找不到默认构造函数;嵌套异常是java.lang.NoSuchMethodException:com.springexample.ExampleBean $InnerBean.()
可能是什么问题呢?我尝试在InnerBean中添加无参数构造函数仍然我收到错误..
谁能帮我?
最佳答案
原文链接:https://www.f2er.com/spring/432034.html