zoukankan      html  css  js  c++  java
  • spring 通过@Value 获取properties文件中设置了属性 ,与@Value # 和$的区别

    spring 获取 properties的值方法

    在spring.xml中配置

    很奇怪的是,在context-param 加载的spring.xml 不能使用 ${xxx}

    必须交给DispatcherServlet 管理的 springMVC.xml才能用?

    要交给springMVC的DispatcherServlet去扫描,而不是spring的监听器ContextLoaderListener去扫描,就可以比较方便的使用“${xxx}”去注入。

    1、使用 $ 获取属性

    @Value("${user.name}")

    private String userName;

    <!--方法1-->
     <context:property-placeholder location="classpath*:info/info.properties" />
    <!--方法2-->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="order" value="1" />
        <property name="locations">
            <list>
                <value>classpath:info/info.properties</value>
            </list>
        </property>
    </bean>

    2、使用 #获取属性

    @Value("#{user.name}")

    private String userName;

    <bean id="prop" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
            <property name="locations"> 
                <array> 
                    <value>classpath:configure.properties</value> 
                </array> 
            </property> 
    </bean>
  • 相关阅读:
    [USACO5.1]二维凸包模板
    HTML 5 Web 存储
    计算两个坐标点的距离(高德or百度)
    Cache的一些总结
    PowerDesigner最基础的使用方法
    MongoDB安装
    MangoDB CSharp Driver
    Linq语法详细
    where用法
    .Net下二进制形式的文件存储与读取
  • 原文地址:https://www.cnblogs.com/lemon-flm/p/8391239.html
Copyright © 2011-2022 走看看