Spring mockMvc doesn't consider validation in my test

后端 未结 3 1529
傲寒
傲寒 2020-12-09 10:03

I am trying to set up an integration testing with mockMvc, and i have a problem with it. Indeed, spring doesn\'t integrate any validation annotation.
For more precisio

3条回答
  •  生来不讨喜
    2020-12-09 10:14

    Ok, I have just found what is responsible for the fact that validation was not consider by mockmvc. It's just a bad dependency in my pom:

    I used

    
        org.hibernate
        hibernate-validator
        5.1.0.Final
    
    

    and when i replaced it by

    
        javax.validation
        validation-api
        1.0.0.GA
    
    
        org.hibernate
        hibernate-validator
        4.1.0.Final
    
    

    the test work just fine!

    the problem is solved, but I am wondering why the problem comes from this part. hibernate-validator 5.1.0.Final include javax validation in transitive dependency, so normally, this problem would never have appeared.

提交回复
热议问题