TomEE throws error "Could not find beans for Type=interface ab.cde.fgh.base.fe.login.LoginService and qualifiers:[]

157 Views Asked by At

I looked through the few other questions related to the error but could not find any advice about this. When running a war file in TomEE and triggering a Filter, the following error occurs:

org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [default] in context with path [/dbdelta] threw exception [java.lang.IllegalStateException: Could not find beans for Type=interface ab.cde.fgh.base.fe.login.LoginService and qualifiers:[]] with root cause
java.lang.IllegalStateException: Could not find beans for Type=interface ab.cde.fgh.base.fe.login.LoginService and qualifiers:[]
    at org.apache.deltaspike.core.api.provider.BeanProvider.getContextualReference(BeanProvider.java:154)
    at org.apache.deltaspike.core.api.provider.BeanProvider.getContextualReference(BeanProvider.java:121)
    at org.apache.deltaspike.core.api.provider.BeanProvider.getContextualReference(BeanProvider.java:100)
    at ab.cde.fgh.base.fe.login.LoginFilter.getLoginService(LoginFilter.java:107)
    at ab.cde.fgh.base.fe.login.LoginFilter.doFilter(LoginFilter.java:68)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at ab.cde.fgh.fe.log.LogFilter.doFilter(LogFilter.java:185)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:750)

The beans should be managed by DeltaSpike. The beans.xml file reads like this:

    <?xml version="1.0" encoding="UTF-8"?>
<beans> xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

The LoginFilter.class mentioned in the TomEE error is this:

package ab.cde.fgh.base.fe.login;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.deltaspike.core.api.provider.BeanProvider;

public class LoginFilter implements Filter {
    private List<String> dropUrls = null;
    private volatile FilterConfig filterConfig;
    private volatile LoginService _delegate;

    public LoginFilter() {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String url = ((HttpServletRequest)servletRequest).getRequestURI();
        if (this.isDroppedUrl(url)) {
            filterChain.doFilter(servletRequest, servletResponse);
        } else {
            this.getLoginService().doFilter(servletRequest, servletResponse, filterChain);
        }

    }

    public void init(FilterConfig filterConfig) throws ServletException {
        this.dropUrls = new ArrayList();

        String dropUrlParam;
        for(int i = 0; (dropUrlParam = filterConfig.getInitParameter("dropurl." + i)) != null; ++i) {
            this.dropUrls.add(dropUrlParam);
        }

        this.filterConfig = filterConfig;
    }

    public void destroy() {
        if (this._delegate != null) {
            this._delegate.destroy();
        }

    }

    private boolean isDroppedUrl(String url) {
        Iterator var2 = this.dropUrls.iterator();

        String stopUrl;
        do {
            if (!var2.hasNext()) {
                return false;
            }

            stopUrl = (String)var2.next();
        } while(!url.contains(stopUrl));

        return true;
    }

    private LoginService getLoginService() throws ServletException {
        if (this._delegate == null) {
            synchronized(this) {
                if (this._delegate == null) {
                    this._delegate = (LoginService)BeanProvider.getContextualReference(LoginService.class, new Annotation[0]);
                    this._delegate.init(this.filterConfig);
                    this.filterConfig = null;
                }
            }
        }

        return this._delegate;
    }
}

The LoginService mentioned is an interface which looks like that:

package ab.cde.fgh.base.fe.login;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public interface LoginService {
    void init(FilterConfig var1) throws ServletException;

    void doFilter(ServletRequest var1, ServletResponse var2, FilterChain var3) throws IOException, ServletException;

    void destroy();
}

The LoginFilter and LoginService are part of an existing codebase and i expect them not to be the source of problem as they work well in other projects. Still given for the sake completeness...

Here is the web.xml, containing the filters:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>myapp</display-name>

    <filter>
        <filter-name>LogFilter</filter-name>
        <filter-class>ab.cde.fgh.base.fe.log.LogFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>LogFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>LoginFilter</filter-name>
        <filter-class>ab.cde.fgh.base.fe.login.LoginFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>LoginFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

I already spent several hours on working on this error and i am quite clueless as to what went wrong here. Any advice is appreciated!

Edits for grammar and clarity

1

There are 1 best solutions below

0
Stef On

It turned out the existing codebase required an implementation of the LoginService interface within the given project. The error was probably due to the fact that no implementation was found for the interface.