zoukankan      html  css  js  c++  java
  • sping配置文件中引入properties文件方式

    <!-- 用于引入 jdbc有配置文件参数 可以使用PropertyPlaceholderConfigurer 或者PropertyOverrideConfigurer -->
      <bean  class="org.springframework.beans.factory.PropertyPlaceholderConfigurer">
              <property name="location">
                  <value>classpath:db.properties</value>
              </property>
      </bean> 

    其中的<properties name="location">中的name必须是location,别的不行,我试了。

    然后我们就在配置dataSource的时候通${key}的方式来调用了

      <!-- 利用上面导入的 配置文件配置 数据源  
      连接池的作用是可以不用经常去获得一个连接
      最主要的是连接可重得使用使得性能有很大的提升
      -->

    db.properties文件

    #mysql
    driverClass=com.mysql.jdbc.Driver
    jdbcUrl=jdbc:mysql://localhost/mybatis?characterEncoding=utf-8
    dialect=org.hibernate.dialect.MySQL5Dialect
    user=root
    password=root
    show_sql=true
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${driverClass}"></property>
            <property name="url" value="${jdbcUrl}"></property>
            <property name="username" value="${user}"></property>
            <property name="password" value="${password}"></property>
        </bean>
  • 相关阅读:
    反射
    注解
    file
    exception(异常)
    MySQL问题
    maven 中 遇到的问题
    Java读取文本数字
    人民币-欧元预测(ARIMA算法)代码
    云平台项目--学习经验--jsrender前端渲染模板
    云平台项目--学习经验--BootstrapValidate表单验证插件
  • 原文地址:https://www.cnblogs.com/suncj/p/4084129.html
Copyright © 2011-2022 走看看