amar2108
amar2108

Reputation: 323

Spring @valid annotation cannot be resolved

I am trying to create a simple JPA framework that performs simple CRUD operations like save employees, delete employees or get a simple employee.

When i am using the valid annotation

    @PostMapping("/employees")
    public Employee createEmployee(@Valid @RequestBody Employee emp)
        return empdao.save(emp);

Its saying that Valid cannot be resolved to a type

I am using these starter dependencies listed below, I dont know if there is a conflict somewhere

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>       
  </dependencies>

Please provide a solution to this, or should i skip the Valid annotation all together,will it work without the valid annotation.

Upvotes: 2

Views: 1901

Answers (1)

M-BNCH
M-BNCH

Reputation: 413

You need validation dependency, this should fix your problem :

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

Upvotes: 4

Related Questions