簡體   English   中英

如何在Wicket中使用Guice Servlet

[英]How to use Guice Servlet with Wicket

在使用Guice Servlet設置我的Wicket項目后,我得到了一個java.lang.IllegalStateException: filter path was not configured 該過濾器路徑配置,雖然。 我錯過了什么嗎?

web.xml中

<?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_2_5.xsd"
     version="2.5">

    <display-name>node-sitter</display-name>

    <listener>
        <listener-class>com.mycompany.wicketapp.inject.ServletConfig</listener-class>
    </listener>
    <filter>
        <description>Initialises Guice</description>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

Guice Servlet聽眾:

public class ServletConfig extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new Servlets());
    }

    private static class Servlets extends ServletModule {

        @Override
        protected void configureServlets() {
            bind(WicketFilter.class).in(Singleton.class);
            filterRegex("/.*").through(WicketFilter.class, withApplicationClass(WicketApplication.class));
        }

        private Map<String, String> withApplicationClass(Class<? extends WebApplication> applicationClass) {
            Map<String, String> initParams = new HashMap<String, String>(1);
            initParams.put("applicationClassName", applicationClass.getName());
            return initParams;
        }
    }
}

堆棧跟蹤(訪問頁面時):

java.lang.IllegalStateException: filter path was not configured
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:124)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194)
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:474)

顯然 ,可以通過向過濾器添加以下init參數來解決此問題:

initParams.put(WicketFilter.FILTER_MAPPING_PARAM, "/*");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM