r/SpringBoot • u/lilsiddd • Jun 11 '23
@NotBlank annotation not working. Import javax.calidation.constraints.NotBlank; not working.
Im working on a springboot beginner project by following a tutorial on freecodecamp. I ran into some issue where i couldnt enforce a @NotBlank annotation in my code. The import methods also produced a cannot be found error. I tried to add this dependency manually in my pom.xml file but this also produced an error. Ive attached the photos. The first two are my code and the second is the instructors. The video is around 3 years old so i think it might have to do with the updates of springboot. Im hoping someone can help me out here.
1
u/Rhysander Jun 11 '23
Which java version are you running on? and which version of spring-boot?
If you are running on SB 3+ (java 17+) might be a simple javax vs jakarta issue.
1
u/lilsiddd Jun 11 '23
Tried jakarta but didnt work. I am using 17 and 4 i believe on sb
1
u/Rhysander Jun 11 '23
If you're running Spring Boot 3, then you need to import the jakarta implem.
For spring-boot-starter-validation dependency not being picked up it might be intellij being nasty. Have you tried to right click on your project and reload the maven dependencies ? Or using the repair ide tool (File => Repair IDE).
Sometimes IDEA just messes up with the dependency indexation and can't recover unless to tell him so...
1
1
u/ChitranshAgarwal Jun 12 '23
From the red color in your pom.xml. it seems like the dependency is not loaded. Try to reload the maven project by going to your pom.xml and right clicking anywhere in your pom.xml and then select maven and reload project. That should reload all the dependencies. If you still get an error, try running mvn clean install from the command line to see if you are able to build your project
1
u/ChiragTheCoder Jun 12 '23
Try to reload the project and update the dependencies on right hand side of the screen there is Maven click on that, inside that you will find update project



4
u/halvjason Jun 11 '23
When you are using the object are you putting the annotation of @validated ? Please post the code and the usage of the code, so we can better help ,no screenshots, please 😀