小编sms*_*eck的帖子

Spring <constructor-arg>元素必须指定ref或value

我遇到了Spring和构造函数注入的问题.我想用name(String)和特殊id(long)创建动态对象.

但是当加载spring.xml文件时会发生异常.

线程"main"java.lang.ExceptionInInitializerError中的异常

由以下原因引起:org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[spring.xml]中定义名称为'someBean'的bean时出错:通过构造函数参数表示的不满意的依赖关系,类型为[long]的索引0:不明确的构造函数参数types - 您是否将正确的bean引用指定为构造函数参数?

我的spring.xml:

    <bean id="someBean" class="someClass" >
        <constructor-arg index="0" type="java.lang.String" value=""/>       
        <constructor-arg index="1" type="long" value=""/>
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

那有什么不对?构造函数arg的索引为1(而不是0,如例外)

java spring constructor-injection

10
推荐指数
1
解决办法
4万
查看次数

转义字符串中的多个不同字符

我想#, $, %, &, \, ^, _, {, }, ~在给定的 Java 字符串中用反斜杠(#变成\#$变成\$等等)转义不同的字符()。

是否可以在不对字符串多次调用String#replaceorString#replaceAll方法的情况下进行归档?

java

0
推荐指数
1
解决办法
690
查看次数

标签 统计

java ×2

constructor-injection ×1

spring ×1