zoukankan      html  css  js  c++  java
  • spring注解中使用properties文件

    一、只读取单个 properties 文件

    1、在 spring 的配置文件中,加入
    引入命名空间:
    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"
     
    内容中写入
    <util:properties id="propertiesReader" location="classpath:test.properties" /> 
     
    2、在类中需要注入的属性实现 setter 和 getter 方法。
     
    3、在 setter 方法前,添加 @Value 注解
    @Value("#{propertiesReader[propertiesName]}")
    propertiesName 为 properties 文件中的键。这样,在容器启动过程中, Spring 将自动注入值。
     
    二、读取多个 properties 文件
    与上类似,只是在配置文件写入的内容不同。
    <bean id="propertiesReader"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
    <list>
    <value>classpath:param.properties</value>
    <value>classpath:base.properties</value>
    </list>
    </property>
    </bean>
  • 相关阅读:
    贪婪算法
    递归 快速排序
    递归 判断数组最大数字
    加法递归
    快速排序
    二分查找
    介绍求解AX=b:可解性与解的结构
    消元法求解线性方程组
    内容说明-线性代数
    gis
  • 原文地址:https://www.cnblogs.com/duffy/p/4332395.html
Copyright © 2011-2022 走看看