zl程序教程

您现在的位置是:首页 >  后端

当前栏目

spring中context:property-placeholder详解编程语言

Spring编程语言 详解 Context Property placeholder
2023-06-13 09:20:35 时间
发现网上对于这个标签的注释过于复杂,这里从适用性角度简短的进行申明。

起首,它是spring3中供应的标签。

只需要在spring的设置装备摆设文件里添加一句:

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

这里location值为参数设置装备摆设文件的位置,参数设置装备摆设文件平日放在src目次下

jdbc设置装备摆设文件:

test.jdbc.driverClassName=com.mysql.jdbc.Driver
test.jdbc.url=jdbc:mysql://localhost:3306/test
test.jdbc.username=root
test.jdbc.password=root

 

如许一来就可认为spring设置装备摆设的bean的属性设置值了

在设置装备摆设文件里这么界说bean:

bean id= testDataSource >  property name= driverClassName value= ${test.jdbc.driverClassName} /
  property name= url value= ${test.jdbc.url} /
  property name= username value= ${test.jdbc.username} /
  property name= password value= ${test.jdbc.password} /
/bean

甚至可以将${ }这种形式的变量用在spring供应的注解傍边,为注解的属性供应值

11697.html

cmysql