【发布时间】:2012-10-27 07:31:54
【问题描述】:
我正在尝试添加另一个名为 captcha 验证过滤器的过滤器以及 spring security 的身份验证过滤器。 我收到此错误。我错过了什么? bean初始化失败;嵌套异常是 org.springframework.beans.ConversionNotSupportedException:无法将类型“java.util.LinkedHashMap”的属性值转换为属性“filterChainMap”所需的类型“java.util.Map”;嵌套异常是 java.lang.IllegalStateException:无法将类型 [com.asu.edu.base.vo.CaptchaFilterVO] 的值转换为属性“filterChainMap[/**][3]”所需的类型 [javax.servlet.Filter] : 未找到匹配的编辑器或转换策略
我的 .java 文件
public class CaptchaFilterVO {
@Autowired
private ReCaptcha reCaptcha = null;
public void doFilterInternal(HttpServletRequest req, HttpServletResponse res,
FilterChain chain) throws IOException, ServletException {
String recaptcha_response = req.getParameter("recaptcha_response_field");
String recaptcha_challenge = req.getParameter("recaptcha_challenge_field");
String remoteAddress = req.getRemoteAddr();
ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer(
remoteAddress, recaptcha_challenge, recaptcha_response);
if (!reCaptchaResponse.isValid()) {
System.out.println("Captcha worong. Please try again.");
}
else
{
System.out.println("Captcha correct. No need to try again.");
}
chain.doFilter(req, res);
}
}
springsecurity.xml
<http auto-config="true">
<!-- intercept-url pattern="/welcome*" access="ROLE_DEPARTMENT_MGR,ROLE_REGULAR_EMP,ROLE_GUEST_USR,ROLE_CORPORATE_MGR" />
<intercept-url pattern="/admin*" access="ROLE_ADMIN" /-->
<intercept-url pattern="/login" filters="none" />
<intercept-url pattern="/resources*" filters="none" />
<intercept-url pattern="/register" filters="none" />
<intercept-url pattern="/logout" filters="none" />
<intercept-url pattern="/loginfailed" filters="none" />
<intercept-url pattern="/admin*" access="ROLE_ADMIN" />
<intercept-url pattern="/Dashboard*" access="ROLE_DEPARTMENT_MGR,ROLE_REGULAR_EMP,ROLE_CORPORATE_MGR" />
<intercept-url pattern="/*" access="IS_AUTHENTICATED_FULLY"/>
<form-login login-page="/login" default-target-url="/"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
<custom-filter ref="captchaVerifierFilter" after="FORM_LOGIN_FILTER"/>
</http>
<beans:bean id="captchaVerifierFilter" class="com.asu.edu.base.vo.CaptchaFilterVO"/>
<beans:bean id="springSecurityFilterChain" class="org.springframework.web.filter.DelegatingFilterProxy"/>
<beans:bean id="myfilterChainProxy" class="org.springframework.security.web.FilterChainProxy">
<filter-chain-map path-type="ant">
<filter-chain pattern="/*" filters="springSecurityFilterChain,captchaVerifierFilter"/>
</filter-chain-map>
</beans:bean>
编辑:公共类 CaptchaFilterVO 扩展 OncePerRequestFilter 实现 javax.servlet.Filter 现在我扩展了 OncePerRequestFilter 类,但现在我面临崩溃。请提供任何帮助。 org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 bean 类 [org.springframework.http.HttpRequest]:指定的类是一个接口 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
【问题讨论】:
-
Could not instantiate bean class [org.springframework.http.HttpRequest]: Specified class is an interface.你可能创建了接口的bean。这是不允许的,因为接口不能被实例化。删除它。 -
我还没有为 HttpRequest 创建 bean。我只创建以下类类型的 bean:
从上面的代码可以看出 CaptchaFilterVO 是一个类 -
提供有关何时引发此异常的更多信息。
-
首次登录页面打开。但是当我尝试使用正确的用户名和密码登录时,我得到了这个异常。基本上,doFilter 被调用,然后是我发布的堆栈跟踪的一部分。
标签: java spring spring-security servlet-filters