Repository navigation
Do not include the validation starter in web starters by default #19550
Description
Activity
- addedtype: enhancementA general enhancementA general enhancementfor: team-attentionAn issue we'd like other members of the team to reviewAn issue we'd like other members of the team to reviewfor: upgrade-attentionAn issue requiring extra attention when upgradingAn issue requiring extra attention when upgrading
on Jan 7, 2020 - removedfor: team-attentionAn issue we'd like other members of the team to reviewAn issue we'd like other members of the team to review
on Jan 10, 2020 We'll do the following:
- remove the
spring-boot-starter-validationfromspring-boot-starter-webby default - change
spring-boot-starter-validationto useorg.glassfish:jakarta.elinstead of the current choice of default implementation - update all the web servers starters to use that same el implementation for all
With this change, we don't need to add a new starter and we can consistently use the same el implementation.
- remove the
I'm surprised to figure out not most projects are not using validations, because all my web apps use them. I had to include this new starter.
I'm wondering what is people using instead?
Reacted by Uno Kim, Durim Kryeziu, Rafal Klys, gaojjx, blowing-in-the-wind, 大胃王, Tadeu Espindola Palermo (CobraDev), Jirka Pinkas, Tomáš Poledný, Christoff Erasmus and 9 moreThe rationale behind this decision is not that most applications aren’t using validation, but rather that there is a significant amount of them and that the (startup and runtime) cost associated with the validation starter is far from negligible.
We usually try to strike the right balance between doing as much as possible with the developer’s intent and keeping setups efficient and lightweight. « Not all web applications should use validation and we want to optimize efficiency » is all that you should read into this decision.
Reacted by Fabricio, Stéphane Nicoll, Juan Moreno, Andrii Maliuta, whahn, Uno Kim, Durim Kryeziu, its-gauravr, copbint, Gurkirat Singh Guliani and 2 moreReacted by Aman Kumar and wjdtn7823This change caught me by surprise a little bit. In upgrading to 2.3.0, I added the validation API, but not the hibernate impl. My unit tests started covering validation started to fail. Without test coverage, might not have caught this.
Maybe consider failing startup if the API is present, and impl is not?
Reacted by min, Tomáš Poledný and Choo Hong@springframeworkguru Any reason why you're not using the
spring-boot-starter-validationinstead of bringing the dependencies manually in your build?Reacted by min and 0xHackThur@bclozel - Just didn't know of it, until I saw this thread. I def will now though.
Reacted by Brian Clozel, Shubham Nagre and LetLetMe5 remaining items
But jakarta-el is now used for compiling jsp, that doesn't look right too. It is present now as a dependency for tomcat starter, not only for validation starter
See - it is compile dependency for tomcat starter, not only for validation starter...
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/2.3.2.RELEASE@mykolap if you've got a solution in mind, please submit a PR and we can reconsider this arrangement.
I don't know how to resolve it properly...
If validation starter is not used - put tomcat-el as a compile dependency to tomcat starter looks good.
But if validation starter is used - we will have 2 libs with el, from jakarta and tomcat, and it should be resolved by excluding one of them...
It doesn't look nice... I will think about better solution, now I see the only way manual resolving, that's what I did in my project...Hi. In my case,
@Validnot work, in GitHub repository specify that in the newest version of spring "Do not include the validation starter in web starters by default ". Now how can i use the validator@Validin the restcontrollersMy Pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> <version>2.4.2</version> </dependency>
My Entity class:
@Entity @Table(name = "todos") @AllArgsConstructor @NoArgsConstructor public class ToDo { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") @Getter @Setter private Integer id; @Column(name = "DESCRIPTION") @Getter @Setter @NotNull @NotEmpty @NotBlank private String description; @Column(name = "DATE") @Getter @Setter @NotNull @NotEmpty @NotBlank private Date date; @Column(name = "PRIORITY") @Getter @Setter @NotNull @NotEmpty @NotBlank private String priority; @Column(name = "FK_USER") @Getter @Setter @NotNull @NotEmpty @NotBlank private String fkUser; @PrePersist void getTimeOperation(){ this.date = new Date(); } }
and my RestController class
@RequestMapping("/todo") public String todoInInput2(@Valid ToDo toDo){ return "Todo description: "+toDo.getDescription()+", todo priority "+toDo.getPriority(); }
A dependency on
spring-boot-starter-validationshould be sufficient. If that's not working and you'd like some help in figuring it out, please come and chat on Gitter or ask a question on Stack Overflow.what if you are using gradle? This tip is not working. springboot 2.4.4
@jdriver2 To which tip are you referring? The build system shouldn't make any difference and adding a dependency on
spring-boot-starter-validationshould be sufficient with both Maven and Gradle. As I said above, if that's not working and you'd like some help in figuring it out, please come and chat on Gitter or ask a question on Stack Overflow.i solved the issue. Using gradle, but required me to restart the IDE. Thanks!
Wanted to point, if you use kotlin, you need to annotate your fields like
@field: NotNull @field:NotEmpty @field:NotBlank, without it - validations won't work using kotlin@Arturo0911 Did you find a solution for your issue? I'm facing the same exact problem as you
i come with the same problem.i use the spring-boot-starter-parent v2.7.5,given the spring-boot-start-validation,but the validation never works,who has the answer ,please.
i get
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.



We've noticed that many applications are not using the validation features in web applications, while validator libraries on the classpath come with a cost.
We could do the following:
spring-boot-starter-validationdependency fromspring-boot-starter-webandspring-boot-starter-webfluxspring-boot-starter-validation-webthat brings in the validation dependencies without thetomcat-embed-elwhich is currently excluded by the web starters