spring 加载资源文件

来源:互联网 发布:mac 下载工具 编辑:程序博客网 时间:2024/05/01 03:06

spring 加载配置文件

通过xml方式加载

1.<context:property-placeholder location="classpath:db-config.properties" ignore-unresolvable="true" />2.<!-- 第二种方式是使用注解的方式注入,主要用在java代码中使用注解注入properties文件中相应的value值 -->  <bean id="prop" class="org.springframework.beans.factory.config.PropertiesFactoryBean">      <property name="locations"><!-- 这里是PropertiesFactoryBean类,它也有个locations属性,也是接收一个数组,跟上面一样          <array>      <value>classpath:public.properties</value>          </array>      </property>  </bean>  

location: 指定了properties的资源位置

原创粉丝点击