gpt4 book ai didi

java - 为什么嵌套类不能用作过滤器的类

转载 作者:行者123 更新时间:2023-11-29 05:33:11 25 4
gpt4 key购买 nike

我正在尝试将嵌套类设置为 Filter 类,但 Intellij IDEA 说它找不到此类,当我尝试在 Web 容器中运行此应用程序时也会发生同样的情况:

<filter>
<filter-name>test</filter-name>
<filter-class>com.web.filters.SimpleFilter.NestedClassFilter</filter-class>
</filter>

我正在尝试使用的类:

public class SimpleFilter implements Filter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;

doFilter(request, response, filterChain);
}

protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException{
}

public void init(FilterConfig filterConfig) throws ServletException {
}

public void destroy() {
}

public static class NestedClassFilter extends SimpleFilter {

@Override
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
filterChain.doFilter(request, response);
}
}
}

我遇到的异常:

Caused By: java.lang.ClassNotFoundException: com.web.filters.SimpleFilter.NestedClassFilter
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

最佳答案

因为你应该在这里使用完全限定的类名

<filter-class>com.web.filters.SimpleFilter.NestedClassFilter</filter-class>

您输入的不是完全限定的类名。应该是

<filter-class>com.web.filters.SimpleFilter$NestedClassFilter</filter-class>

注意 $

See here for details why.

关于java - 为什么嵌套类不能用作过滤器的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20402661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com