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();
            }
    
        }
    }
  • 相关阅读:
    eas之Uuid和BOSUuid 区别
    BOS工具之BOS应用框架
    eas之EAS手工打包及快速部署工具
    S-HR体验中心
    wafII笔记
    eas之MrpUI
    S-HR快速查看shr日志
    S-HR二开基础
    linux安装mysql
    linux安装tomcat
  • 原文地址:https://www.cnblogs.com/zhang188660586/p/11557296.html
Copyright © 2011-2022 走看看