-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not include the validation starter in web starters by default #19550
Comments
We'll do the following:
With this change, we don't need to add a new starter and we can consistently use the same el implementation. |
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? |
The 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. |
This 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? |
@springframeworkguru Any reason why you're not using the |
@bclozel - Just didn't know of it, until I saw this thread. I def will now though. |
+1 for add some warning or even fail to start, it's strange to silent skip valid check if valid stuff not work. |
I don't understand why it has been changed. If the people who don't want to use validation can exclude the |
@Saljack Please see this comment above for the reasoning behind the change. |
Decision about using jakarta-el instead of default el from tomcat was not the best choice for our project... |
@mkopylec that's unfortunate. Did you raise an issue with the el library about this? Could you edit your comment linking to that issue for other community members? We chose the Jakarta implementation here as validation doesn't necessarily happen in a web application (so with a server) and pushing the Tomcat implementation for apps using another Servlet container didn't feel right. |
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... |
@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... |
Hi. In my case, My 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 |
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 |
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 |
@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-validation
dependency fromspring-boot-starter-web
andspring-boot-starter-webflux
spring-boot-starter-validation-web
that brings in the validation dependencies without thetomcat-embed-el
which is currently excluded by the web startersThe text was updated successfully, but these errors were encountered: