gpt4 book ai didi

java - 为什么 Autowiring 不适用于这个 Spring MVC String bean 属性?

转载 作者:行者123 更新时间:2023-12-04 06:20:42 25 4
gpt4 key购买 nike

@Autowired
private String defaultLanguage;

当我尝试 @Autowire defaultLanguage领域 CountryBean类如下:
<beans:bean id="countryBean" class="geoapp.CountryBean">
<beans:property name="defaultLanguage" value="English" />
</beans:bean>

我收到此错误:
Error creating bean with name 'CountryBean': 
Injection of autowired dependencies failed;
nested exception is
org.springframework.beans.factory.BeanCreationException:
Could not autowire field:
private java.lang.String geoapp.CountryBean.defaultLanguage;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [java.lang.String] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for
this dependency.
Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}:

当它说 No matching bean of type [java.lang.String] found for dependency ,我想知道是否还有什么我需要说来让它知道值 EnglishString ?

最佳答案

由于您通过 xml 显式指定属性值,因此无需使用 AutoWired 注释。

关于java - 为什么 Autowiring 不适用于这个 Spring MVC String bean 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6617315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com