spring 框架的xml文件如何读取properties文件数据
来源:互联网 发布:中国facebook知乎 编辑:程序博客网 时间:2024/05/18 01:51
spring 框架的xml文件如何读取properties文件数据
第一步:在spring配置文件中
注意:value可以多配置几个properties文件
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<value>/db.properties</value>
</list>
</property>
</bean>
第二步:
在src目录下面建立db.properties文件
user=sa
password=sa
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost:1433;databaseName=DB1
第三步:
在spring的配置文件中通过EL表达式的形式调用
${user}
<?xml version="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<beanid="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<value>/db.properties</value>
</list>
</property>
</bean>
<beanid="datasource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<propertyname="driverClassName"
value="${driver}">
</property>
<property name="url"
value="${url}">
</property>
<property name="username"value="${user}"></property>
<property name="password"value="${password}"></property>
</bean>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="datasource" />
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<propertyname="mappingResources">
<list>
<value>entity/Users.hbm.xml</value>
</list>
</property>
</bean>
<beanid="UsersDAO" class="dao.UsersDAO">
<propertyname="sessionFactory">
<refbean="sessionFactory" />
</property>
</bean>
</beans>
- spring 框架的xml文件如何读取properties文件数据
- spring 框架的xml文件如何读取properties文件数据
- spring 框架的xml文件如何读取properties文件数据
- spring 框架的xml文件如何读取properties文件数据
- XML文件中如何读取xxx.properties文件中的数据
- spring如何读取properties文件
- spring的xml配置文件读取properties文件中的属性
- 没有spring框架下,读取properties文件的办法
- 《记录问题》spring注解如何读取.properties文件数据,以及spring静态变量读取.properties文件错误
- Properties读取xml文件
- Spring 如何读取properties文件内容
- Spring 如何读取properties文件内容
- Spring 如何读取properties文件内容
- Spring 如何读取properties文件内容
- Spring 读取 properties文件
- Spring 读取properties文件
- spring读取properties文件
- spring 读取properties文件
- 位图排序——编程珠玑
- 设计模式 (三)抽象工厂模式(AbstractFactory)
- flex入门学习之7 DateField
- VS2010 代码前出现虚线的问题
- 关于eclipse没有GBK选项
- spring 框架的xml文件如何读取properties文件数据
- Android2.3.3系统开发一个在线OTA功能下载文件功能
- Oracle10g JDBC ojdbc14 DATE类型hibernate查询时分秒问题(纠结困扰了半天,汗)
- 介绍了8种非常YD用源代码去调试DLL的方法
- Struts 框架中的时间问题
- JS刷新当前页面
- 数据文件自动扩展只能到32G?
- postgreSQL hot stand by
- 进程通信 共享数据段