当前位置: 首页 > news >正文

十堰网站建设价格竞价托管外包费用

十堰网站建设价格,竞价托管外包费用,建站平台wp,青岛大型网站设计公司需求:将数据库连接四要素提取到properties配置文件,spring来加载配置信息并使用这些信息来完成属性注入。第三方bean属性优化的思路如下: 1.在resources下创建一个jdbc.properties(文件的名称可以任意) 2.将数据库连接四要素配置到配置文件中 3.在Spr…

需求:将数据库连接四要素提取到properties配置文件,spring来加载配置信息并使用这些信息来完成属性注入。第三方bean属性优化的思路如下:

1.在resources下创建一个jdbc.properties(文件的名称可以任意)

2.将数据库连接四要素配置到配置文件中

3.在Spring的配置文件中加载properties文件

4.使用加载到的值实现属性注入

其中第3,4步骤是需要重点关注,具体是如何实现。

实现步骤

步骤1:准备properties配置文件

resources下创建一个jdbc.properties文件,并添加对应的属性键值对

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/spring_db
jdbc.username=root
jdbc.password=root

步骤2:开启context命名空间

在applicationContext.xml中开context命名空间

<?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/springcontext.xsd">
</beans>

步骤3:加载properties配置文件

在配置文件中使用context命名空间下的标签来加载properties配置文件

<context:property-placeholder location="jdbc.properties"/>

步骤4:完成属性注入

使用${key}来读取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/springcontext.xsd">
<context:property-placeholder location="jdbc.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>

至此,读取外部properties配置文件中的内容就已经完成。

http://www.mnyf.cn/news/50665.html

相关文章:

  • 如何将网站指向404自助发稿
  • 功能网站建设宁波网络营销公司有哪些
  • 阿里云建站方案关键词seo资源
  • 资金盘做网站模板网站如何建站
  • 外贸网站建设公司流程关键词排名优化软件
  • wordpress图片水印插件系统优化工具
  • 廊坊模板网站建设研究生培训机构排名
  • 开了个网站用年份做名字好吗优化 保证排名
  • 深圳市移动端网站建设全部视频支持代表手机浏览器
  • 做柜子设计的网站设计百度首页排名优化公司
  • seo 优化技术难度大吗杭州网站优化平台
  • dede 网站打开自动加html模板之家
  • 南京房地产网站建设网络广告推广
  • 学做网站能赚多少钱如何让百度能查到自己
  • 网站排名权重怎么做跨境电商培训机构哪个靠谱
  • 专业做酒的网站有哪些成免费crm软件有哪些优点
  • 新锐媒体网站建设方案龙华线上推广
  • 福鼎建设局网站网站怎么接广告
  • 做骗子网站网站排名工具
  • 网站开发总跳转至404页面如何提高网站排名seo
  • 政府网站版面布局结构杭州网络
  • 葫芦岛网站建设seo推广技术
  • php网站开发web实例泉州全网推广
  • 网站优化推广的方法网店seo
  • 平潭做网站网站建设的公司
  • 哈尔滨网站建设网络公司我国网络营销现状分析
  • 上海大型网站建设郑州seo价格
  • 网站怎样免费推广广告联盟接广告
  • 自助建站什么意思产品推广方案范文500字
  • 百度网址安全检测中心免费seo在线工具