通过ServletContextEvent加载spring的application.xml
2015-09-14 10:30
573 查看
1. 配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.aspire.mms.sqsjb.rtgs_webapp.servlet.InitializationListener</listener-class>
</listener>
2加载
public void contextInitialized(ServletContextEvent servletContextEvent) {
LogAgent.sysRuntimeLogger.info("Real-Time Generate Service startup.");
ApplicationContext applicationContext = (ApplicationContext) servletContextEvent.getServletContext().getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
LogAgent.sysRuntimeLogger.info("Get spring application context {}", applicationContext);
servletContextEvent.getServletContext().setAttribute("app", applicationContext);
}
public void contextInitialized(ServletContextEvent event)
{
//获取applicationContext文件所在的路径;
String path = event.getServletContext().getRealPath(File.separator)
+ event.getServletContext().getInitParameter("applicationContextConfigName");
// 把applicationContext.xml文件路径存在application作用域中;
event.getServletContext().setAttribute("applicationContextPath",path);
....
}
3 使用
app = (ApplicationContext) getServletConfig().getServletContext().getAttribute("app");
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.aspire.mms.sqsjb.rtgs_webapp.servlet.InitializationListener</listener-class>
</listener>
2加载
public void contextInitialized(ServletContextEvent servletContextEvent) {
LogAgent.sysRuntimeLogger.info("Real-Time Generate Service startup.");
ApplicationContext applicationContext = (ApplicationContext) servletContextEvent.getServletContext().getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
LogAgent.sysRuntimeLogger.info("Get spring application context {}", applicationContext);
servletContextEvent.getServletContext().setAttribute("app", applicationContext);
}
public void contextInitialized(ServletContextEvent event)
{
//获取applicationContext文件所在的路径;
String path = event.getServletContext().getRealPath(File.separator)
+ event.getServletContext().getInitParameter("applicationContextConfigName");
// 把applicationContext.xml文件路径存在application作用域中;
event.getServletContext().setAttribute("applicationContextPath",path);
....
}
3 使用
app = (ApplicationContext) getServletConfig().getServletContext().getAttribute("app");
相关文章推荐
- Android版本(1.0-7.0)
- iOS Label添加删除线
- Android中让多个线程顺序执行探究
- iOS 简介eventKit框架(译) 日历提醒应用等
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
- Android中让多个线程顺序执行探究
- Unity 游戏开发技巧集锦之创建透明的材质
- Android-监听软键盘状态
- iOS view的抗拉伸和抗压缩属性
- iOS学习笔记:instancetype关联返回类型
- Android之Json转换利器Gson之实例一-简单对象转化和带泛型的List转化
- Android控件之CheckBox、RadioButton用法实例分析
- Android studio appcompat-v7 更新23.0.x版本后出现问题
- 第一个app项目
- android:scaleType属性
- android进度条的使用(PrograssBar,SeekBar,RatingBar)
- Android开源测试框架学习
- android手机客户端上传文件,java servlet服务器端接收并保存到服务器
- Android开源测试框架学习
- Android数据库安全解决方案,使用SQLCipher进行加解密