java 构造函数报错_java spring 构造器注入报错

在尝试使用Spring框架进行构造器注入时遇到了BeanCreationException,报错信息提示无法解析匹配的构造函数。问题出在XML配置文件中可能没有正确指定bean的构造参数。在已提供的代码中,`GeetingServiceBean`类有两个构造函数,一个无参,一个带参数。解决此问题的方法是明确指定构造器注入时的参数。
摘要由CSDN通过智能技术生成

packagecn.csdn.hr.service;publicclassGeetingServiceBeanimplementsGreetingService{privateintgreeting;publicvoidsetGreeting(intgreeting){this.greeting=greeting;}publicGeeti...

package cn.csdn.hr.service;

public class GeetingServiceBean implements GreetingService {

private int greeting;

public void setGreeting(int greeting) {

this.greeting = greeting;

}

public GeetingServiceBean(int greeting) {

this.greeting = greeting;

}

public GeetingServiceBean() {

}

public void sayGeeting() {

System.out.println(greeting);

}

}

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

用set方式不会报错,但是用构造器缺报错了:Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geetingServiceBean' defined in class path resource [applicationContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值