• Spring @Value注解问题


    xml配置了下面标签:<context:property-placeholder location="classpath:xxx.properties" />

    用spring的@Value注解

    @Value(value="#{redis.url}")
     private String url = "";

    报错,大致为track:

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recommendController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xiu.xclk.web.controller.RecommendController.url; 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 'redis' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

    改用下面标签:

    <util:properties id="settings" location="classpath:xclkweb.properties"></util:properties>

    java代码改为:

    @Value("#{settings['redis.url']}")

    private String url = "";

    OK

    要用util标签,要引入util的xsd

    xmlns:util="http://www.springframework.org/schema/util"

    xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"

    来源:https://blog.csdn.net/daihui05/article/details/7560570

  • 相关阅读:
    java 获取pdf内容
    超快的maven setting文件
    MQTT-CN MQTT协议中文版
    Another maybe monad library for ruby
    [Game-0001] 新手引导逻辑梳理
    [Erlang-0016][aque_tcp] 一个 Erlang TCP 组件
    [Erlang-0015][Lager] Erlang日志框架Lager简析
    LeetCode.1217-交换芯片(Play with Chips)
    LeetCode.1207-唯一的元素出现次数(Unique Number of Occurrences)
    LeetCode.1200-最小绝对值差(Minimum Absolute Difference)
  • 原文地址:https://www.cnblogs.com/kongxc/p/9092353.html
Copyright © 2020-2023  润新知