spring加载properties文件(xml)

爱被打了一巴掌 2024-05-23 14:12 174阅读 0赞

spring加载properties文件

1、开启context命名空间,添加以下三行
在这里插入图片描述

  1. xmlns:context="http://www.springframework.org/schema/context
  2. http://www.springframework.org/schema/context
  3. http://www.springframework.org/schema/context/spring-context.xsd

2、使用context命名空间加载所有properties文件

  1. <!-- 不加载系统属性-->
  2. <!-- <context:property-placeholder location="jdbc.properties" system-properties-mode="NEVER"/>-->
  3. <context:property-placeholder location="classpath*:*.properties"/>

3、使用属性占位符${}读取properties文件中的属性

  1. <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  2. <property name="driverClass" value="${jdbc.driver}"/>
  3. <property name="jdbcUrl" value="${jdbc.url}"/>
  4. <property name="user" value="${jdbc.username}"/>
  5. <property name="password" value="${jdbc.password}"/>
  6. </bean>

发表评论

表情:
评论列表 (有 0 条评论,174人围观)

还没有评论,来说两句吧...

相关阅读