gpt4 book ai didi

java - 如何在 Wicket 中使用 Guice Servlet

转载 作者:搜寻专家 更新时间:2023-11-01 01:29:38 26 4
gpt4 key购买 nike

在使用 Guice Servlet 设置我的 Wicket 项目后,我得到一个 java.lang.IllegalStateException: filter path was not configured。不过,过滤器路径配置的。我错过了什么吗?

网络.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)

最佳答案

Apparently ,可以通过向过滤器添加以下初始化参数来解决此问题:

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

关于java - 如何在 Wicket 中使用 Guice Servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5494395/

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