1

エンティティの注釈を使用して休止状態バリデーターを使用して、Spring MVC から検証を行っています。

エンティティに BigDecimal プロパティがあり、範囲値の検証を確認する必要があります。以下のように

@NotNull(message = "errors.range_1_5_Trades.mandatory")
@Pattern(regexp = "(^$[0-9])", message = "errors.only.numbersAllowed")
@Range(min = 1, max = 5, message = "errors.invalid.range")
@Column(name = "FEE_LESS_THAN_5")
private BigDecimal feeLessThan_5;

しかし、Spring Controller で @Valid アノテーションを使用してこれを検証すると、以下のように例外がスローされます

javax.validation.UnexpectedTypeException: No validator could be found for type: java.math.BigDecimal
    at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:383)
    at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:364)
    at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:313)
    at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:144)
    at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117)
    at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:452)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361)
    at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313)
    at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139)
    at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:86)
    at org.springframework.validation.DataBinder.validate(DataBinder.java:711)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:807)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:359)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:937)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3810)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:183)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
4

1 に答える 1

8

@Pattern is only allowed on String values a valid validator for @Pattern with a Number argument isn't there.

于 2013-10-02T10:10:36.740 に答える