spring父子容器与读取properties文件
来源:互联网 发布:淘宝有种苗吗 编辑:程序博客网 时间:2024/06/05 07:53
读取properties文件中的内容,可以使用@Value
比如
@Value("${url}")
public String url;
properties文件内容是 url=xxxxxx
但是它只能在它所在容器中使用。比如spring容器中加载了properties文件,但你这个注解使用在springmvc容器(子容器)的Controller中,那么是获取不到的。
-------------------------------------------------
关于父子容器:
子容器能够访问父容器的资源,父容器能够访问子容器的资源。
我们在web.xml中其实配置的就是父子容器org.springframework.web.context.ContextLoaderListener和org.springframework.web.servlet.DispatcherServlet。因为我们在DispatcherServlet中的param-value是spring-servlet.xml,所以,即使你在applicationContext.xml中加载了controller也是没用的,只有spring-servlet.xml中加载controller才有用。
-------------------------------------------------
因为@Value("${url}")这种用法。所以有两种方式使用,
第一种,如果你要在子容器中使用@Value,那么就得把properties文件在spring-servlet.xml中引入。
第二种,因为子容器能访问父容器资源,那就在子容器中创建一个@Service或@Repository等注解的类,专门封装properties文件中的信息。那么子容器可以通过@Autowired对象去得到properties文件中信息。
推荐使用第二种方式。
- spring父子容器与读取properties文件
- Spring与SpringMVC父子容器
- spring和springmvc的父子容器间访问properties文件内容
- Spring 读取 properties文件
- Spring 读取properties文件
- spring读取properties文件
- spring 读取properties文件
- spring读取properties文件
- spring读取properties文件
- Spring 读取properties文件
- Spring 与 SpringMVC 父子容器问题
- spring 读取properties属性文件
- spring读取properties文件信息
- spring文件读取properties文件属性
- Spring 读取properties文件内容
- Spring读取properties文件内容
- spring配置文件读取properties文件
- 使用spring读取properties文件
- Enhanced Deep Residual Networks for Single Image Super-Resolution
- 详解Android studio的构建文件build.gradle
- 面试常考数据结构与算法
- kotlin学习笔记
- Egret游戏通用开发框架
- spring父子容器与读取properties文件
- Spring MVC Flash 属性解决属性丢失
- POJ 3264 (ST表的简单使用)
- Tomcat无法编译
- 多个TOMCAT实例,分端口添加到系统服务
- ecshop 数据库结构和表的字段介绍
- 把一个数组里的组合全部列出
- 验证码
- android activity lanuchMode