spring mybatis整合读取配置文件

来源:互联网 发布:windows窗口编程 编辑:程序博客网 时间:2024/05/16 01:55

第一种:采用$符读取配置文件中的内容

<?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"       xmlns:util="http://www.springframework.org/schema/util"       xmlns:task="http://www.springframework.org/schema/task"       xsi:schemaLocation="       http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd      http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-3.1.xsd       http://www.springframework.org/schema/task       http://www.springframework.org/schema/task/spring-task-3.1.xsd       http://www.springframework.org/schema/util       http://www.springframework.org/schema/util/spring-util-2.0.xsd"
  <!-- 系统环境变量定义 -->    <context:property-placeholder location="classpath:conf.properties" ignore-unresolvable="true" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" parent="parentdataSource">    <property name="url" value="${jdbc.url}" />    <property name="username" value="${jdbc.username}" />    <property name="password" value="${jdbc.password}" /></bean>   
此方式自动装配方式不能是byName,会出现读取不到配置文件中内容的情况

第二种:采用#方式读取配置文件中的内容

<?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"       xmlns:util="http://www.springframework.org/schema/util"       xmlns:task="http://www.springframework.org/schema/task"       xsi:schemaLocation="       http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd      http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-3.1.xsd       http://www.springframework.org/schema/task       http://www.springframework.org/schema/task/spring-task-3.1.xsd       http://www.springframework.org/schema/util       http://www.springframework.org/schema/util/spring-util-2.0.xsd"       default-autowire="byName">    <!-- 系统环境变量定义 -->    <context:property-placeholder location="classpath:conf.properties" ignore-unresolvable="true" />    <util:properties id="properties" location="classpath:conf.properties"/>


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" parent="parentdataSource">    <property name="url" value="#{properties['jdbc.url']}" />    <property name="username" value="#{properties['jdbc.username']}" />    <property name="password" value="#{properties['jdbc.password']}" /></bean>   


0 0
原创粉丝点击