zoukankan      html  css  js  c++  java
  • Spring阶段性学习总结(七)引用properties文件的属性

    <?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">
        <!--引入外部文件-->
        <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
    
        <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="user" value="${user}"></property>
            <property name="password" value="${password}"></property>
            <property name="driverClass" value="${driverclass}"></property>
            <property name="jdbcUrl" value="${jdbcurl}"></property>
        </bean>
    
    </beans>
    package SpringProperties;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import javax.sql.DataSource;
    import java.sql.SQLException;
    
    public class Main {
        public static void main(String[] args) {
            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("SpringProperties/beans-properties.xml");
            DataSource datasource = (DataSource) ctx.getBean("datasource");
            try {
                System.out.println(datasource.getConnection());
            } catch (SQLException e) {
                e.printStackTrace();
            }
    
        }
    }
  • 相关阅读:
    【JZOJ4244】yi【贪心】
    【JZOJ4244】yi【贪心】
    基本赋值运算符
    自增自减运算符
    字符串的+操作
    算术运算符
    数据类型转换
    键盘输入使用
    基本数据类型长度
    变量
  • 原文地址:https://www.cnblogs.com/zhang188660586/p/11557296.html
Copyright © 2011-2022 走看看