Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取筛选器类中的自动连线服务_Java_Spring Mvc_Filter_Autowired - Fatal编程技术网

Java 获取筛选器类中的自动连线服务

Java 获取筛选器类中的自动连线服务,java,spring-mvc,filter,autowired,Java,Spring Mvc,Filter,Autowired,有一个错误: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registeredatorg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252)at org.apache.catalina.core.ApplicationFilterCh

有一个错误:

java.lang.IllegalStateException: 
No WebApplicationContext found: no ContextLoaderListener registeredatorg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
我的
web.xml
config被声明为
DelegatingFilterProxy
。如果有不同的身份验证规则,如何在筛选器中写入?通过那些不同的url名称

public class SecurityFilter implements Filter{
@Autowired
private TokenService tokenService;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    String token = request.getParameter("token");//:TODO}}
spring配置为:

<bean id="securityFilter" class="xx.filter.SecurityFilter"></bean>


过滤器类不是一个spring非旋转类,因此不会加载任何与spring相关的依赖类。理想情况下,如果您将UserFilter注释为spring组件,那么您的@autowired依赖项也将加载。

您的问题一点也不清楚。