I'm trying to set nested class as Filter class but Intellij IDEA said that it can not found this class also the same happens when I'm trying to run this application in web container:

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

And class that I'm trying to use:

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);
        }
    }
}

Exception that I've got:

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)
有帮助吗?

解决方案

Because you are supposed to use the fully qualified class name in here

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

What you've put isn't the fully qualified class name. It should be

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

Note the $.

See here for details why.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top