Spring引入外部属性文件配置数据库连接的步骤详解

网友投稿 687 2023-02-18

Spring引入外部属性文件配置数据库连接的步骤详解

Spring引入外部属性文件配置数据库连接的步骤详解

直接配置数据库的信息

xml配置文件直接配置:

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:util="http://springframework.org/schema/util"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/utiwMqPQl http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:util="http://springframework.org/schema/util"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/utiwMqPQl http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd">

一般不会这样用,不便于修改,我们看下面的引入外部属性文件配置的方法

引入外部属性文件配置数据库连接

1.引入德鲁伊连接池jar包

(1)导入进来一个druid-1.0.9.jar,直接复制粘贴到当前目录就可以了。

(2http://)引入到当前项目。

2.配置德鲁伊连接池

(1)新建一个jdbc.properties文件,写数据库的相关信息。

jdbc.properties:

jdbc.driverClass=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://127.0.0.1:3306/userDb?characterEncoding=utf8&useUnicode=true&useSSL=false

jdbc.username=root

jdbc.password=root

(2)新建一个配置文件。

bean6.xml:

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:util="http://springframework.org/schema/util"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/util http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/context http://springframework.org/schema/contexwMqPQt/spring-context.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:util="http://springframework.org/schema/util"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/util http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/context http://springframework.org/schema/contexwMqPQt/spring-context.xsd">

完成以上步骤,就完成了引入外部属性文件配置数据库连接。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:移动应用开发实验报告(移动应用开发实验报告和作业)
下一篇:SpringBoot整合JDBC的实现
相关文章

 发表评论

暂时没有评论,来抢沙发吧~