dajek
dajek

Reputation: 181

Javax validation exception when migrating to Wildfly 8.1

I am getting the following exception:

javax.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not alter the parameter constraint configuration

when deploying my application on Wildfly 8.1 server. The project is deploying and working well on a previous, JBoss 7.1 application server. Do I need to make changes to the code or could there be some problem with the configuration?

Upvotes: 4

Views: 12090

Answers (4)

shuai yan
shuai yan

Reputation: 35

like @Drd said. I wrote setter method param with @Valid in child class, after remove this annotation, the error is disappeared.

void setAA(@Valid AA aa) {}

Upvotes: 0

DrD
DrD

Reputation: 41

I face the same problem in my spring boot project, you should move validation annotation where use in override method into super class or interface.

Upvotes: 4

Vikash Kumar
Vikash Kumar

Reputation: 127

javax.validation.ConstraintDeclarationException is raised if you add parameter constraints to a method which overrides or implements a super-type method. This behavior is mandated by the Bean Validation spec (see http://beanvalidation.org/1.1/spec/#constraintdeclarationvalidationprocess-methodlevelconstraints-inheritance) in order to obey to the Liskov substitution principle:

for example below code Illegally declared parameter constraints on sub class and it will throw above exception:

public class OrderService {

void placeOrder(String customerCode, Item item, int quantity) { [...] }
} 

public class SimpleOrderService extends OrderService {

@Override
public void placeOrder(
    @NotNull @Size(min=3, max=20) String customerCode,
    @NotNull Item item,
    @Min(1) int quantity) {
    [...]
}

}

Upvotes: 9

dajek
dajek

Reputation: 181

I couldn't find any configuration to help with this problem so I removed parameter constraints from implementation classes, which solved the problem.

Upvotes: -3

Related Questions