加载外部的 properties 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
"
>
<bean class="com.yuelin.impl.BookDaoImpl" id="bookDao" autowire="byType"/>

<bean class="com.yuelin.impl.BookServiceDaoImpl" id="bookServiceDao" autowire="byType"/>

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

<!-- location:
1. 加载多个文件 可以直接在后面用 , 分割 添加多个文件名称 : location="jdbc.properties, msg.properties"
2. 加载所有的文件 当前包下的所有属性文件 location="*.properties"
3. 加载properties 的标准格式, location="classpath:*.properties" (一般用这种)
4. 加载从类路径 甚至 jar 包里面的的搜索 location="classpath*:*.properties"
-->
<context:property-placeholder location="classpath*:*.properties" />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>