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();
            }
    
        }
    }
  • 相关阅读:
    后台架构设计—数据存储层
    Linux应用程序基础
    Linux文件管理命令笔记
    CentOS7搭建LAMP实战
    (ospf、rip、isis、EIGRP)常见的动态路由协议简介
    python while 循环语句
    获取linux帮助命令
    破解linux虚拟机的密码
    gawk编程语言
    MySQL触发器在PHP项目中用来做信息备份、恢复和清空的方法介绍
  • 原文地址:https://www.cnblogs.com/zhang188660586/p/11557296.html
Copyright © 2011-2022 走看看