加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 设置属性值时出错;嵌套异常是org.springframework.bean

发布时间:2020-12-15 01:31:59 所属栏目:大数据 来源:网络整理
导读:我试图使用Spring实用程序ResultSetExtractor从MySQL数据库获取数据,但我得到以下异常: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edao' defined in class path resource [app

我试图使用Spring实用程序ResultSetExtractor从MySQL数据库获取数据,但我得到以下异常:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'edao' defined in class path resource [applicationContext2.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcTemplate' of bean class [org.resultset.EmployeeDao]: Bean property 'jdbcTemplate' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1344)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.context.support.ClassPathXmlApplicationContext.

Employee.java

public class Employee {

    private int id;  
    private String name;  
    private float salary;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getSalary() {
        return salary;
    }
    public void setSalary(float salary) {
        this.salary = salary;
    }
    public Employee(int id,String name,float salary) {
        super();
        this.id = id;
        this.name = name;
        this.salary = salary;
    } 

    public Employee()
    {

    }

}

EmployeeDao.java

public class EmployeeDao {  
private JdbcTemplate template;  

public void setTemplate(JdbcTemplate template) {  
    this.template = template;  
}  

public List

Test.java

public class Test {  

public static void main(String[] args) {  
  ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext2.xml");  
  EmployeeDao dao=(EmployeeDao)ctx.getBean("edao");  
  List

和applicationContext2.xml

这些都是我正在使用的java文件.它说setter的返回类型与getter不匹配,但我检查了它,并且它在那里是正确的.

最佳答案
问题在于

< bean id =“edao”class =“org.resultset.EmployeeDao”>
?????< property name =“jdbcTemplate”ref =“jdbcTemplate”>< / property>
< /豆腐>

尝试将name =“jdbcTemplate”更改为name =“template”.由于你已经将名称命名为jdbcTemplate,spring将在EmployeeDao类中搜索名为setJdbcTemplate()的setter方法,但是你拥有的acutal方法是setTemplate()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读