关于在filter中获取WebApplicationContext的实践
网上很多说法,诸如:
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-context.xml
</param-value>
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
之类的,尝试了之后报错:No WebApplicationContext found: no ContextLoaderListener registered?
最后的解决方法是:
this.initWebApplicationContext(getServletContext());
另外一个顺带提一下,classpath指向WEB-INF/classes/
关于在filter中获取WebApplicationContext的实践的更多相关文章
- filter中获取spring bean
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import ja ...
- web过滤器中获取请求的参数(content-type:multipart/form-data)
1.前言: 1.1 在使用springMVC中,需要在过滤器中获取请求中的参数token,根据token判断请求是否合法: 1.2 通过requst.getParameter(key)方法获得参数值; ...
- web项目中获取spring的bean对象
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架,如何在程序中不通过注解的形式(@Resource.@Autowired)获取Spring配置的bean呢? Bean工厂(c ...
- springboot中使用ContextLoaderListener.getCurrentWebApplicationContext();获取WebApplicationContext为空问题
WebApplicationContext applicationContext = ContextLoaderListener.getCurrentWebApplicationContext(); ...
- 从servlet中获取spring的WebApplicationContext
需要做一个参数初始化类,当web应用被加载时从数据库里取出相关的参数设置 ,并把这些参数放置到application里,jsp页面可以从中取出. 1.在web.xml中配置: <servlet& ...
- 解决在Filter中读取Request中的流后,后续controller或restful接口中无法获取流的问题
首先我们来描述一下在开发中遇到的问题,场景如下: 比如我们要拦截所有请求,获取请求中的某个参数,进行相应的逻辑处理:比如我要获取所有请求中的公共参数 token,clientVersion等等:这个时 ...
- 在Java filter中调用service层方法
在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...
- 如何在Java Filter 中注入 Service
在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...
- Lazy<T>在Entity Framework中的性能优化实践
Lazy<T>在Entity Framework中的性能优化实践(附源码) 2013-10-27 18:12 by JustRun, 328 阅读, 4 评论, 收藏, 编辑 在使用EF的 ...
随机推荐
- Java--常识
一:J2SE/J2ME/J2EE Java2平台包括:标准版(J2SE).企业版(J2EE)和微缩版(J2ME)三个版本.J2SE,J2ME和J2EE,这也就是SunONE(Open NetEnvir ...
- A - Combination Lock
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Scroog ...
- 使用命令把类打成jar包
测试用类 public class Hello { public static void main(String[] args) { System.out.println("hello wo ...
- 大白话5分钟带你走进人工智能-第二十九节集成学习之随机森林随机方式 ,out of bag data及代码(2)
大白话5分钟带你走进人工智能-第二十九节集成学习之随机森林随机方式 ,out of bag data及代码(2) 上一节中我们讲解了随机森林的基本概念,本节的话我们讲解随机森 ...
- iOS 中 常用的第三方库
现在对于我们 iOS 开发来说,基本上说不可能不使用第三方轮子啦,毕竟没那么多时间,而且自己造的轮子往往想着成为上图中的最后一个,结果却成了上图中第二个或第一个啦,当然大公司另当别论.下面我从之前用过 ...
- iOS代码封装成.a文件(封装SDK)
在众多开源的大神的博客里经整理如下:(已测试ok) 一.描述一下 Build ActiveArchitecture Only设置成YES: Architectures按Xcode默认配置,arm64向 ...
- Spring中配置Dbutils
<!--配置QueryRunner--> <bean id="runner" class="org.apache.commons.dbutils.Que ...
- WindowsService服务程序开发 安装和卸载
安装服务:installutil.exe E:\XTestDemo\X_15_WindowsService\bin\Debug\X_15_WindowsService.exe 卸载服务:install ...
- HDU1501【简单DP】
题意: 从a串和b串中顺序地取出是否能组成c串: 思路: dp[i][j] 代表从a串中取了i个,b串中取了j个的情况: #include <bits/stdc++.h> using na ...
- php 发送邮件(实例)
html部分 <!DOCTYPE html> <html> <head> <title></title> <script type=& ...