利用Spring的ServletContextAware给ServletContext初始化数据
来源:互联网 发布:网络分布式继电器接线 编辑:程序博客网 时间:2024/06/06 14:18
package com.xxximport org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Lazy;import org.springframework.stereotype.Component;import org.springframework.web.context.ServletContextAware;@Component@Lazy(false)public class PropertyHolder implements ServletContextAware{ private static ServletContext servletContext; private static String uploadDir; // 生成的js文件存放目录 private static String jsGenerateDir; /** * 给上下文设置值 */ @Override public void setServletContext(ServletContext servletContext) { PropertyHolder.servletContext = servletContext; servletContext.setAttribute("ctx", servletContext.getContextPath()); servletContext.setAttribute("uploadDir", uploadDir); //TODO 初始化任何值 } //从配置文件(/application.properties)给属性赋值,其中upload.dir 配置文件在项目根路径,里面定义了upload.dir才能赋值成功,否则初始化事值为null @Value("${upload.dir}") public void setUploadDir(String uploadDir) { PropertyHolder.uploadDir = uploadDir; } //TODO 从配置文件初始化任何属性 //It's so easy! let's get it;}
阅读全文
0 0
- 利用Spring的ServletContextAware给ServletContext初始化数据
- 获得spring初始化的bean和ServletContext
- ServletContextAware的作用
- (18)servletContext应用:获取web应用的初始化参数、实现servlet转发、利用servletContext对象读取资源文件
- Spring中ServletContextAware接口使用理解
- spring中ApplicationContextAware接口ServletContextAware接口
- spring中ServletContextAware接口使用理解 (转载)
- 利用Spring BeanPostProcessor 初始化时加载数据到缓存
- 利用spring监听ApplicationListener实现初始化业务数据
- 利用ServletContext对象实现多个Servlet之间的数据共享
- Spring中,给静态变量初始化的问题
- Spring数据初始化
- 利用ServletContext实现页面访问量的统计
- Spring Batch 初始化数据,清空数据的做法
- oracle利用游标数据初始化
- 在spring的bean中获取ServletContext
- 在spring的bean中获取ServletContext
- Spring中DispacherServlet、WebApplicationContext、ServletContext的关系
- Spring事务管理只对出现运行期异常进行回滚
- 系统延时与定时任务
- <time>标签里面的时间有什么实际意义?
- bzoj1997[Hnoi2010]Planar 2-SAT
- Vue.js学习笔记:计算属性
- 利用Spring的ServletContextAware给ServletContext初始化数据
- 素数nyoj--(素数距离)
- Python正则表达式指南 (转自:AstralWind)
- c++堆排序
- uva 1368
- [BZOJ]3944: Sum
- 51nod 1080 两个数的平方和
- C++的特点和程序实例
- spring 定时器 @Component 执行两次 问题解决