Spring MVC with hibernate validation doesn't work

前端 未结 3 1040
遥遥无期
遥遥无期 2021-01-22 01:29

I have some problems with hibernate validations with Spring. I did everything as explained in an online tutorial, but it\'s not working and I just go to the next page without va

相关标签:
3条回答
  • 2021-01-22 01:55

    Note: solution based on the IntelliJ IDEA IDE

    If not using build tools such as Gradle or Maven, this could be related to the IDE's behavior during the compilation and build of the solution when manually adding libraries (project dependencies).

    Regardless of having the library files manually included in the project and indexed by the IDE by adding those manually through Project Structure > Libraries, those aren't going to be included automatically in the compilation output of your build process.

    In order to make sure libraries you included are assembled together with the Spring MVC solution do the following:

    • go to File > Project Structure > Artifacts (from the left pane)

    • expand the WEB-INF/lib directory under Output Layout tab

    • highlight lib directory and add corresponding Hibernate artifacts by clicking the + button and selecting Library Files

    • after selecting the library from project libraries, select OK, Apply and you are ready to go

    Now, when you rebuild the solution and Run the server, your assembled output (build) will contain all additionally added artifacts (libs) such as Hibernate validation.

    When using IntelliJ IDEA's builder to compile Java-based project, it uses its own project model, configuration and built-in mechanism to assemble the output application, so such steps like I mentioned are required.

    This is mandatory here In contrast to compiling and building such Java projects using Gradle or Maven where those use their own underlying build process and run specific tasks to generate the output based on the build.gradle or pom.xml configuration holding all of the config values and dependencies.

    0 讨论(0)
  • 2021-01-22 01:59

    Add setter to your Customer class.
    Without setter your class does not be populated.

    0 讨论(0)
  • 2021-01-22 02:11

    Add hibernate-validator in your classpath if it does not exist already. If you are using any build tool like gradle or maven just add hibernate-validator to dependencies.

    For example:

    Gradle:

    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.13.Final'
    

    Maven:

    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.13.Final</version>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题