zoukankan      html  css  js  c++  java
  • 读取properties的简单方法,使用@Configuration

    1. 配置类代码如下
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class Config {
        @Value("${test}")
        private String test;
    
        public String getTest() {
            return test;
        }
        
    }

      2.Spring配置

    <!-- 获取配置属性值 -->
        <bean id="configProperties"
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="locations">
                <list>
                    <value>classpath:app/env/config.properties</value>
                    <value>classpath:app/config/database.properties</value>
                    <value>classpath:app/config/redis.properties</value>            
                </list>
            </property>
        </bean>
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
            <property name="properties" ref="configProperties" />
        </bean>        

      3.测试接口类

    @Service
    public class SsoInterface {
    
        @Autowired
        private SsoConfig SsoConfig;
    
    
      public void test(){
              System.out.println(SsoConfig.getTest());
        }  
    
    }

    最后就能输出 需要的配置文件对应信息

    版权声明:如需转载,请注明!PS:如是转载随便,请忽略
  • 相关阅读:
    sublime开启vim模式
    git命令行界面
    搬进Github
    【POJ 2886】Who Gets the Most Candies?
    【UVA 1451】Average
    【CodeForces 625A】Guest From the Past
    【ZOJ 3480】Duck Typing
    【POJ 3320】Jessica's Reading Problemc(尺取法)
    【HDU 1445】Ride to School
    【HDU 5578】Friendship of Frog
  • 原文地址:https://www.cnblogs.com/zwdx/p/7682953.html
Copyright © 2011-2022 走看看