失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Spring配置文件中引入properties文件

Spring配置文件中引入properties文件

时间:2019-04-02 01:26:02

相关推荐

Spring配置文件中引入properties文件

jdbc.properties文件中有信息如下:

username=rooturl=jdbc:mysql://localhost:3306/qw?characterEncoding=utf8driver=com.mysql.jdbc.Driverpwd=123456789

在Spring配置文件中引入properties文件有两种写法:

1、直接使用context:property-placeholder>标签,把jdbc.properties文件路径写进去就可以了。如:

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

用法是:${...}

如果我要取url的数据,直接写成这样:${url}

2、配置成bean的形式,如:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><!--可以配置多个资源文件 --><list><value>classpath:jdbc.properties</value></list></property></bean>

用法同上。

如果觉得《Spring配置文件中引入properties文件》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。