Spring MVC 通过@Value注解读取.properties配置

来源:互联网 发布:退货还给淘宝客佣金吗 编辑:程序博客网 时间:2024/05/16 10:26

第一步:application.properties配置文件中建立内容:

ios.test.appKey=824f1694e205e2973933482cios.test.masterSecret=206399b1ce5e75236bcf0490


第二步:配置applicationContext-commom.xml文件:

<bean id="configProperties" class="com.sf.egmas.isn.framework.SystemProperties">       <property name="locations">    <array><value>classpath:application.properties</value>    </array></property></bean><bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">         <property name="properties" ref="configProperties" />     </bean> 
第三步:在java代码类读取配置文件的内容:

    @Value("#{configProperties['jiguang.hmt.ios.appKey']}")    private String hmtIosAppKey;        @Value("#{configProperties['jiguang.hmt.ios.masterSecret']}")    private String hmtIosMasterSecret;


0 0