zl程序教程

您现在的位置是:首页 >  后端

当前栏目

浅谈Spring6引入外部Jdbc.properties配置文件

Spring6JDBC配置文件 浅谈 引入 外部 properties
2023-06-13 09:17:24 时间
Class类
Jdbc.properties配置文件
SpringConfig.xml配置

xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context

<!--引入外部的properties文件-->
                                         <!--    location默认从类的路径下开始加载资源-->
<context:property-placeholder location="jdbc.properties"/>

<!--    配置数据源-->
    <bean id="ds" class="com.spring6.jdbc.MyDataSource">
<!--        取值${key}-->
        <property name="driver" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="usernamme" value="${jdbc.usernamme}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>