javax验证错误代码问题

时间:2010-12-09 08:01:55

标签: validation spring-mvc

我正在使用javax验证注释并得到这个奇怪的错误

java.lang.IllegalArgumentException: can't parse argument number error.tnimi
    java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
    java.text.MessageFormat.applyPattern(MessageFormat.java:458)
    java.text.MessageFormat.<init>(MessageFormat.java:368)
    org.springframework.context.support.MessageSourceSupport.createMessageFormat(MessageSourceSupport.java:115)
    org.springframework.context.support.MessageSourceSupport.formatMessage(MessageSourceSupport.java:99)
    org.springframework.context.support.AbstractMessageSource.renderDefaultMessage(AbstractMessageSource.java:275)
    org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:152)
    org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:71)
    org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:1125)
    org.springframework.web.servlet.support.RequestContext.getMessage(RequestContext.java:559)
    org.springframework.web.servlet.support.BindStatus.initErrorMessages(BindStatus.java:177)
    org.springframework.web.servlet.support.BindStatus.getErrorMessages(BindStatus.java:273)
    org.springframework.web.servlet.tags.form.ErrorsTag.exposeAttributes(ErrorsTag.java:172)
    org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.writeTagContent(AbstractHtmlElementBodyTag.java:48)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:91)
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:78)
    org.apache.jsp.WEB_002dINF.jsp.addmaterial_jsp._jspService(addmaterial_jsp.java:579)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
    org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:650)
    org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:644)
    org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
    org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
    org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
    org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
    org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
    org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
    org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
    org.apache.jsp.WEB_002dINF.tiles.root_jsp._jspx_meth_tiles_005finsertAttribute_005f1(root_jsp.java:203)
    org.apache.jsp.WEB_002dINF.tiles.root_jsp._jspService(root_jsp.java:88)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
    org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
    org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:678)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:633)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
    org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:100)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
    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:355)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:110)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

我的注释是

@NotEmpty (message ="{error.tnimi}")
    public String getName() {

应该是对的。怎么办?

1 个答案:

答案 0 :(得分:0)

默认情况下,Spring不会将JSR-303 MessageInterpolator配置为使用您定义的MessageSource,因此您无法使用此语法来访问自己MessageSource的消息。

典型方法是使用MessageSource中的默认消息代码,例如NotEmpty.objectName.name,而不是message属性中明确指定的代码。

从Spring 3.0.4和Hibernate Validator 4.1开始,您可以配置消息插补器以使用您的消息源see javadoc