SpringMVC加载配置Properties文件的几种方式
来源:互联网 发布:网络大电影票房排行榜 编辑:程序博客网 时间:2024/05/19 16:35
最近开发的项目使用了SpringMVC的框架,用下来感觉SpringMVC的代码实现的非常优雅,功能也非常强大,
网上介绍Controller参数绑定、URL映射的文章都很多了,写这篇博客主要总结一下SpringMVC加载配置Properties文件的几种方式
1.通过context:property-placeholde实现配置文件加载
1.1、在spring.xml中加入context相关引用
1.2、引入jdbc配置文件
1.3、jdbc.properties的配置如下
1.4、在spring-mybatis.xml中引用jdbc中的配置
1.5、在java类中引用jdbc.properties中的配置
1.6、在controller中调用
1.7、测试
在ie中输入http://localhost:8080/testWeb/service/test 或http://localhost:8080/testWeb/service/test2
返回如下结果:
注:通过context:property-placeholde加载多个配置文件
只需在第1.2步中将多个配置文件以逗号分隔即可
2、通过util:properties实现配置文件加载
2.1、在spring.xml中加入util相关引用
2.2、 引入config配置文件
2.3、config.properties的配置如下
2.4、在java类中引用config中的配置
2.5、在controller中调用
2.6、测试
在ie中输入http://localhost:8080/testWeb/service2/test
返回如下结果:
3.直接在Java类中通过注解实现配置文件加载
3.1、在java类中引入配置文件
3.2、在controller中调用}3.3、测试
在ie中输入http://localhost:8080/testWeb/service2/test
返回如下结果:
最后附上spring.xml的完整配置:
- SpringMVC加载配置Properties文件的几种方式
- SpringMVC加载配置Properties文件的几种方式
- SpringMVC加载配置Properties文件的几种方式
- SpringMVC加载配置Properties文件的几种方式
- SpringMVC加载配置Properties文件的几种方式
- SpringMVC加载配置Properties文件的几种方式
- springmvc加载properties文件的几种方式
- 加载.properties文件的几种方式
- properties文件读取的几种方式
- Properties 文件 读取 的几种方式
- 读取properties文件的几种方式
- SpringMvc 加载配置.Properties文件中的方法
- properties文件的配置加载
- SpringMVC配置几种方式
- java几种读取.properties文件的方式
- 读取properties文件的几种常用方式
- java几种读取.properties文件的方式
- java 加载文件的几种方式
- 5.Draftjs 学习笔记-自定义控件(多媒体)
- java 线程 --- Thread,Runnable,Callable 基础学习
- Linux pip换源
- 分布式系统架构
- Linux命令执行顺序
- SpringMVC加载配置Properties文件的几种方式
- Java 字符串拼接方式性能比较
- python filter design
- 微服务之分布式跟踪系统(springboot+zipkin)
- Add Two Numbers
- Java应用梯度下降求解线性SVM模型参考代码
- psi and index do not match问题
- 人脸识别
- Python网络数据采集(1)