张西军 2008-08-29 11:32
浏览 201
已采纳

spring数组注入问题

[code="java"]
package com.spdb.conf;

public class ChangeRptConf {
private String[] orgIdArray;

public String[] getOrgIdArray() {
    return orgIdArray;
}

public void setOrgIdArray(String[] orgIdArray) {
    this.orgIdArray = orgIdArray;
}

}

[/code]

[code="xml"]



9401
9402



[/code]

测试代码
[code="java"]
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

    ChangeRptConf conf = (ChangeRptConf) ctx.getBean("changeRptConfBean");

    String[] x = conf.getOrgIdArray();
    for (int i = 0; i < x.length; i++) {
        System.out.println(x[i]);
    }

[/code]

具体报错:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'changeRptConfBean' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [java.lang.String[]] for property 'orgIdArray'; nested exception is java.lang.IllegalArgumentException: Original must not be null

难道是bean配置有问题吗?

  • 写回答

1条回答 默认 最新

  • iteye_14762 2008-08-29 12:18
    关注

    我将你代码在我机器上运行过, 没有问题!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?