Spring(3.1.0版本)@Value:从配置xml读取自动接线异常
代码对类路径中的配置文件具有以下引用Spring(3.1.0版本)@Value:从配置xml读取自动接线异常,spring,autowired,Spring,Autowired,代码对类路径中的配置文件具有以下引用 .... @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Repository public class TestTaxes implements TaxIntface { @Autowired protected ContxtManager contxtManager; @Autowired protected TxEngLoader txEng; @Value("#{path
....
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Repository
public class TestTaxes implements TaxIntface {
@Autowired
protected ContxtManager contxtManager;
@Autowired
protected TxEngLoader txEng;
@Value("#{paths}")
List<String> paths;
....
感谢您的帮助,谢谢 这是因为属性是映射而不是列表。 如果要从属性列表中获取字符串,则需要执行以下操作: 路径和属性 在java类中,您需要执行以下操作:
public class TestTaxes implements TaxIntface {
@Value("#{paths['value.list.properties']}")
List<String> paths;
我自己已经找到了解决这个问题的办法。
所有设置和配置均正确;但是@ImportResource缺少config.xml条目,它有路径值列表。为什么不简单地使用@Autowired和@Qualifier或@Resource和bean名称?@Value{paths}。。。零件在另一个产品代码中,我无法更改。我在我的代码中扩展TestTaxes类,这就是它在尝试初始化父类时失败的地方…我尝试将@Scopevalue=step,proxyMode=ScopedProxyMode.TARGET_类使用到我创建的子类,该子类工作正常,但它在父类TestTaxes上卡住了。。。
Error creating bean with name 'testTaxes': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: java.util.List com.x.y.z.TestTaxes.paths;
nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed;
nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'paths' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
value.list.properties=string1,string2,string3
public class TestTaxes implements TaxIntface {
@Value("#{paths['value.list.properties']}")
List<String> paths;