如何在spring中读取properties配置文件里面的信息
来源:互联网 发布:ubuntu虚拟机屏幕小 编辑:程序博客网 时间:2024/06/05 00:21
1.首先。我们要先在spring配置文件中。定义一个专门读取properties文件的类. 例: <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:jdbc.properties</value> <!--要是有多个配置文件,只需在这里继续添加即可 --> </list> </property> </bean>
这里为什么用locations(还有一个location)是因为。一般来说。我们的项目里面。配置文件可能存在多个。就算是只有一个。那将来新添加的话。只需在下面再加一个value标签即可。而不必再重新改动太多。(当然。性能上是否有影响,这个以当前这种服务器的配置来说。是基科可以忽略不计的)。然后我们就可以在jdbc.properties文件中填写具体的配置信息了。 <!-- 配置C3P0数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>${jdbc.driverClassName}</value> </property> <property name="jdbcUrl"> <value>${jdbc.url}</value> </property> <property name="user"> <value>${jdbc.username}</value> </property> <property name="password"> <value>${jdbc.password}</value> </property> </bean>jdbc.properties文件写的信息。jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/testjdbc.username=rootjdbc.password=root附加一个列子: <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>file:/data/pc-config/passport.properties</value> <value>classpath:memcached.properties</value> </list> </property> </bean> classpath:是指的当前类文件的目录下。 file:在window下是指的当前分区(比如你的项目是放在d盘,则是在d:/data/pc-config/passport.properties) 在linux下,则是当前路径下的文件/data/pc-config/passport.properties
0 0
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 在spring中读取properties配置文件里面的信息
- Spring -- 如何在spring中读取properties配置文件里面的信息
- 自定义类在spring中读取properties配置文件信息
- 通过Spring读取properties配置文件的信息 Spring 读取properties
- spring中如何读取.properties配置文件
- 在spring中读取properties配置文件
- 配置文件中如何读取properties的配置文件
- spring 中如何读取properties的中属性信息
- 在spring配置文件中设置读取jdbc.properties配置文件的时候报错
- spring配置文件读取jdbc.properties的配置信息
- 读取.properties配置文件信息
- 读取properties配置文件信息
- Spring配置文件中读取properties文件的属性
- redis中hashtable 的 rehash/ resizing 策略
- Android Studio连接GitHub报错Cannot run program "git.exe": CreateProcess error=2, 系统找不到指定的文件。
- binutils
- oracle分区
- 深度学习模型之各种caffe版本(Linux和windows)的网址和配置
- 如何在spring中读取properties配置文件里面的信息
- 初识ButterKnife——ButterKnife的用法
- Some keyword
- Centos7.2系统下安装VirtualBox缺少compiler-gcc6.h
- 进程
- C语言格式输出函数printf()详解
- 大型网站架构之分布式消息队列
- Socket——实现简单的一对一服务器端与客户端聊天功能
- Qt编写OCX插件注册错误