设计网站怎么做,百度最新财报,wordpress发布图片错位,百度云CDN支持wordpressspring引入外部属性文件 有时候我们并不想把所有的配置信息都放到spring的配置文件中#xff0c;这样的话也不太好维护#xff0c;比如说数据库的信息 bean namedataSource classcom.alibaba.druid.pool.DruidDataSource init-methodinit这样的话也不太好维护比如说数据库的信息 bean namedataSource classcom.alibaba.druid.pool.DruidDataSource init-methodinit destroy-methodclose property nameurl valuejdbc:mysql://localhost:3306/test?useUnicodetruecharacterEncodingutf-8/ property nameusername valueroot/ property namepassword value123456/ /bean 这样配置当然也可以只是要去修改spring配置文件的时候由于spring的配置文件内容太多不太方便所以有时候会引入外部的属性文件 可以使用context:property-placeholder标签来进行引入 beans xmlnshttp://www.springframework.org/schema/beans xmlns:contexthttp://www.springframework.org/schema/context xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd !-- 引入外部配置文件 -- context:property-placeholder locationclasspath:db.properties/ bean namedataSource classcom.alibaba.druid.pool.DruidDataSource init-methodinit destroy-methodclose property nameurl value${url}/ property nameusername value${username}/ property namepassword value${password}/ /bean db.properties属性文件 urljdbc:mysql://localhost:3306/test?useUnicodetruecharacterEncodingutf-8
usernameroot
password123456context:property-placeholder会生成一个PropertySourcesPlaceholderConfigurer类来解析占位符 https://zhhll.icu/2021/框架/spring/基础/15.spring引入外部属性文件/ 本文由 mdnice 多平台发布