zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [TimLinux] Python 函数(2)
    [TimLinux] Python nonlocal和global的作用
    [TimLinux] Python 装饰器
    fragment+viepager 的简单暴力的切换方式
    EditText键盘弹出时,会将布局底部的导航条顶上去(解决方法之一)
    EditText取消自动调用键盘事件(方法之一)
    Fragment滑动切换简单案例
    ListAdapter列表适配器
    ListView列表的简单案例
    ViewPager图片切换的简单案例
  • 原文地址:https://www.cnblogs.com/kongxc/p/9092353.html
Copyright © 2011-2022 走看看