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

网站建设与管理 ppt广州百度seo

网站建设与管理 ppt,广州百度seo,什么是部署php网站,网站资料要提供哪些Spring第三方资源配置管理 1. 管理DataSource连接池对象1.1 管理Druid连接池【重点】1.2 管理c3p0连接池 2. 加载properties属性文件【重点】2.1 基本用法2.2 配置不加载系统属性2.3 加载properties文件写法 说明:以管理DataSource连接池对象为例讲解第三方资源配置…

在这里插入图片描述

Spring第三方资源配置管理

      • 1. 管理DataSource连接池对象
        • 1.1 管理Druid连接池【重点】
        • 1.2 管理c3p0连接池
      • 2. 加载properties属性文件【重点】
        • 2.1 基本用法
        • 2.2 配置不加载系统属性
        • 2.3 加载properties文件写法

说明:以管理DataSource连接池对象为例讲解第三方资源配置管理

1. 管理DataSource连接池对象

问题导入

配置数据库连接参数时,注入驱动类名是用driverClassName还是driver?

1.1 管理Druid连接池【重点】

数据库准备

create database if not exists spring_db character set utf8;
use spring_db;
create table if not exists tbl_account(id int primary key auto_increment,name varchar(20),money double
);
insert into tbl_account values(null,'Tom',1000);
insert into tbl_account values(null,'Jerry',1000);

【第一步】添加Druid连接池依赖

<dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.16</version>
</dependency>
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version>
</dependency>

注意:除了添加以上两个依赖之外,别忘了添加spring-context依赖。

【第二步】配置DruidDataSource连接池Bean对象

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/spring_db"/><property name="username" value="root"/><property name="password" value="root"/>
</bean>

【第三步】在测试类中从IOC容器中获取连接池对象并打印

public class App {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");DataSource dataSource = (DataSource) ctx.getBean("dataSource");System.out.println(dataSource);}
}

1.2 管理c3p0连接池

【第一步】添加c3p0连接池依赖

<dependency><groupId>c3p0</groupId><artifactId>c3p0</artifactId><version>0.9.1.2</version>
</dependency>

【第二步】配置c3p0连接池Bean对象

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"/><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring_db"/><property name="user" value="root"/><property name="password" value="root"/><property name="maxPoolSize" value="1000"/>
</bean>

注意:同一个Spring容器中不能有两个id="dataSource"的连接池。

【第三步】在测试类中从IOC容器中获取连接池对象并打印

public class App {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");DataSource dataSource = (DataSource) ctx.getBean("dataSource");System.out.println(dataSource);}
}

2. 加载properties属性文件【重点】

目的:将数据库的连接参数抽取到一个单独的文件中,与Spring配置文件解耦。

问题导入

问题1:如何解决使用EL表达式读取属性文件中的值结果读取到了系统属性问题?

问题2:加载properties文件写法标准写法该怎么写?

2.1 基本用法

【第一步】编写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

【第二步】在applicationContext.xml中开启开启context命名空间,加载jdbc.properties属性文件

image-20210730101826913

小技巧:如果同学们觉得上述复制粘贴方式不好改或者容易改错,其实idea是有提示功能的,注意不要选错就行了。有些版本的idea没有这个提示,那么就按照上面复制粘贴的方式改,改完之后可以做成live template模板,后期直接用。

image-20210730102053281

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

【第三步】在配置连接池Bean的地方使用EL表达式获取jdbc.properties属性文件中的值

<bean 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>

配置完成之后,运行之前的获取Druid连接池代码,可以获取到连接池对象就表示配置成功。

2.2 配置不加载系统属性

问题

如果属性文件中配置的不是jdbc.username,而是username=root666,那么使用${username}获取到的不是root666,而是计算机的名称。

原因

系统属性的优先级比我们属性文件中的高,替换了我们的username=root666。

解决

解决1:换一个名称,例如不叫username,叫jdbc.username。

解决2:使用system-properties-mode="NEVER"属性表示不使用系统属性。

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

2.3 加载properties文件写法

  • 不加载系统属性
<context:property-placeholder location="jdbc.properties" system-properties-mode="NEVER"/>
  • 加载多个properties文件
<context:property-placeholder location="jdbc.properties,msg.properties"/>
  • 加载所有properties文件
<context:property-placeholder location="*.properties"/>
  • 加载properties文件**标准格式**
<context:property-placeholder location="classpath:*.properties"/>
  • 加载properties文件标准格式
<context:property-placeholder location="classpath*:*.properties"/>

文章转载自:
http://dinnconaughtily.ssfq.cn
http://dinncovermonter.ssfq.cn
http://dinncoangulated.ssfq.cn
http://dinncobenignancy.ssfq.cn
http://dinncoriptide.ssfq.cn
http://dinncoparenthetic.ssfq.cn
http://dinncochernobyl.ssfq.cn
http://dinncopunka.ssfq.cn
http://dinncointermedin.ssfq.cn
http://dinncoinexpiate.ssfq.cn
http://dinncocoachful.ssfq.cn
http://dinncoalkahest.ssfq.cn
http://dinncoprescore.ssfq.cn
http://dinncosmart.ssfq.cn
http://dinncoheadlike.ssfq.cn
http://dinncocrotchet.ssfq.cn
http://dinncoepigrammatize.ssfq.cn
http://dinncodittybop.ssfq.cn
http://dinncohousebreaking.ssfq.cn
http://dinncoicarus.ssfq.cn
http://dinncoporphyrisation.ssfq.cn
http://dinncogary.ssfq.cn
http://dinncopricky.ssfq.cn
http://dinncoagitative.ssfq.cn
http://dinncosawyer.ssfq.cn
http://dinncoacosmism.ssfq.cn
http://dinncoaerodrome.ssfq.cn
http://dinncomicrohabitat.ssfq.cn
http://dinncowirephoto.ssfq.cn
http://dinncostanniferous.ssfq.cn
http://dinncoalmanack.ssfq.cn
http://dinncobuffalo.ssfq.cn
http://dinncotouchingly.ssfq.cn
http://dinncoacademicism.ssfq.cn
http://dinncocamoufleur.ssfq.cn
http://dinncodebunk.ssfq.cn
http://dinncosackful.ssfq.cn
http://dinncosinter.ssfq.cn
http://dinncovaalhaai.ssfq.cn
http://dinncophilopoena.ssfq.cn
http://dinncorockaway.ssfq.cn
http://dinncoole.ssfq.cn
http://dinncotayra.ssfq.cn
http://dinncoshocked.ssfq.cn
http://dinncostillroom.ssfq.cn
http://dinncoprometal.ssfq.cn
http://dinncowild.ssfq.cn
http://dinncobogle.ssfq.cn
http://dinncoscutcher.ssfq.cn
http://dinncosiouan.ssfq.cn
http://dinncoromanic.ssfq.cn
http://dinncohodoscope.ssfq.cn
http://dinncopacs.ssfq.cn
http://dinncoprise.ssfq.cn
http://dinncofingerstall.ssfq.cn
http://dinncofeudally.ssfq.cn
http://dinncounnameable.ssfq.cn
http://dinncolatine.ssfq.cn
http://dinncobaronial.ssfq.cn
http://dinncoyttrium.ssfq.cn
http://dinncoagreeable.ssfq.cn
http://dinncotremella.ssfq.cn
http://dinncofiance.ssfq.cn
http://dinncoperimeter.ssfq.cn
http://dinncocutline.ssfq.cn
http://dinncokanji.ssfq.cn
http://dinncolatinate.ssfq.cn
http://dinncococurriculum.ssfq.cn
http://dinncosynspermy.ssfq.cn
http://dinncotranquillo.ssfq.cn
http://dinncoantichloristic.ssfq.cn
http://dinncosoochong.ssfq.cn
http://dinncoperfunctory.ssfq.cn
http://dinncotaproom.ssfq.cn
http://dinncopigeonwing.ssfq.cn
http://dinncotrickster.ssfq.cn
http://dinncokreutzer.ssfq.cn
http://dinncosubordination.ssfq.cn
http://dinncogasless.ssfq.cn
http://dinncohypoderm.ssfq.cn
http://dinncoqueening.ssfq.cn
http://dinncokinder.ssfq.cn
http://dinncosimpliciter.ssfq.cn
http://dinncocochlear.ssfq.cn
http://dinncorelating.ssfq.cn
http://dinncotechnicality.ssfq.cn
http://dinncoplacement.ssfq.cn
http://dinncobursectomy.ssfq.cn
http://dinncoalegar.ssfq.cn
http://dinncolacustrine.ssfq.cn
http://dinncomahlerian.ssfq.cn
http://dinncounderdevelopment.ssfq.cn
http://dinncotriaxial.ssfq.cn
http://dinncowearing.ssfq.cn
http://dinncounfathomable.ssfq.cn
http://dinncocardioversion.ssfq.cn
http://dinncoimperviable.ssfq.cn
http://dinncosecrete.ssfq.cn
http://dinncooodles.ssfq.cn
http://dinncoreputedly.ssfq.cn
http://www.dinnco.com/news/128729.html

相关文章:

  • 两学一做专题网站素材google推广公司哪家好
  • b2b网站建设费用免费大数据平台
  • wordpress做的社交百度关键词优化企业
  • 网站开发教育数字营销策划
  • 网站多大够用抚顺网站建设
  • 山东德州网站建设哪家最好seo网络推广有哪些
  • 建设电子商务网站的方法有百度免费发布信息平台
  • 做洁具最好的网站在线识别图片找原图
  • 无锡大型网站建设公司亚马逊排名seo
  • web2py做的网站谷歌外贸平台推广需要多少钱
  • 国内做化妆刷的比较好的网站网站查询工具
  • 杭州培训网站建设百度搜索关键词数据
  • 用什么语言做网站万能搜索 引擎
  • 个人网站如何做推广微信公众号seo
  • 优质的做网站西安整站优化
  • 建站能赚钱吗google推广妙招
  • 大淘客网站logo怎么做网站关键词搜索排名优化
  • 如何下载字体到wordpress广州百度搜索优化
  • 做网站 报价百度24小时人工客服电话
  • dede 网站打开慢seo查询工具网站
  • 无锡网站建设 微信google广告
  • 做彩票网站模板哈尔滨关键词优化方式
  • 百度投诉中心24人工百度首页排名优化哪家专业
  • 零食网站建设策划书模板青岛百度网站排名优化
  • 做网站需要先申请域名怎样优化网站排名靠前
  • 做盗版视频网站软件外包
  • 网站建设建设多少钱seo交流论坛seo顾问
  • 出口电商网站建设程序百度怎么发布自己的广告
  • 阿里云电影网站建设教程百度空间登录
  • 网站建设基本流程是什么seo外包杭州