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

java – 为什么Spring报告工厂方法arg不明确?

发布时间:2020-12-15 05:20:58 所属栏目:Java 来源:网络整理
导读:我正在尝试创建这个bean: bean id="myBean" class="java.lang.String" factory-method="valueOf" constructor-arg name="obj" value="a string" type="java.lang.Object"//bean 我希望Spring在创建bean时使用此方法java.lang.String #valueOf(Object obj).
我正在尝试创建这个bean:

<bean id="myBean" class="java.lang.String" factory-method="valueOf">
    <constructor-arg name="obj" value="a string" type="java.lang.Object"/>
</bean>

我希望Spring在创建bean时使用此方法java.lang.String #valueOf(Object obj).

我明白了:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [char[]]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [char[]]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [boolean]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [long]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [char]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [double]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [float]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [int]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in class path resource [META-INF/test-contexts/testManualDependencyBundleResolverContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.Object]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?

为什么?我想我已经指定了Spring所需的一切来解决我希望它使用的正确方法.

解决方法

只需删除名称属性,名称的XSD文档说:

Only needed to avoid ambiguities,e.g. in case of 2 arguments of 
 the exact same type. Note: This requires debug symbols to be 
 stored in the class file in order to introspect argument names!

(编辑:李大同)

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

    推荐文章
      热点阅读