Comments (4)
This comment on a Spring Framework issue might also be relevant.
from spring-boot.
There were some notable changes in this area in Spring Framework 6.1 (spring-projects/spring-framework#29825). The change that you're seeing may be as a result of a refinement of those changes in a Spring Framework patch release. It's hard to be certain with the level of detail that you've currently provided. You could try using spring.version
to override the version of Spring Framework that's used to see if this changes the behavior. If it does, then this will have to be investigated by the Spring Framework team. If it does not then we'll need some more information in the form of a minimal sample that we can use to reproduce the behavior you have described.
from spring-boot.
Hi,
@scottfrederick thank you for the link. This issue seems to be duplicate of that one.
@PostMapping("/test1")
ResponseEntity<String> test1(@Valid @RequestBody TestModel testModel) {
return ResponseEntity.ok().build();
}
throws MethodArgumentNotValidException
but
@PostMapping("/test2/{param}")
ResponseEntity<String> test2(
@NotNull @PathVariable(name = "param") String param,
@Valid @RequestBody TestModel testModel) {
return ResponseEntity.ok().build();
}
throws HandlerMethodValidationException
My pom.xml is fairly simple:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<relativePath/>
</parent>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<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>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
TestApplication.class:
package com.example.test;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.annotation.HandlerMethodValidationException;
@ControllerAdvice
@RestController
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
@PostMapping("/test1")
ResponseEntity<String> test1(@Valid @RequestBody TestModel testModel) {
return ResponseEntity.ok().build();
}
@PostMapping("/test2/{param}")
ResponseEntity<String> test2(
@NotNull @PathVariable(name = "param") String param,
@Valid @RequestBody TestModel testModel) {
return ResponseEntity.ok().build();
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> handleException(final MethodArgumentNotValidException ex) {
return ResponseEntity.badRequest().build();
}
@ExceptionHandler
public ResponseEntity<String> handleUncaughtExceptions(final HandlerMethodValidationException ex) {
return ResponseEntity.badRequest().build();
}
@Data
public static class TestModel {
@Size(min = 3)
private String name;
}
}
In spring-boot-starter-parent version 3.2.1, both cases are handled by MethodArgumentNotValidException
from spring-boot.
Thanks, @pepavesely. Closing as a duplicate of spring-projects/spring-framework#32396.
from spring-boot.
Related Issues (20)
- Test Gradle plugin against Gradle 8.7
- Test Gradle plugin against Gradle 8.7
- Buildpacks do not support Docker with containerd image store
- x-www-form-urlencoded escaping leads to truncated request HOT 1
- Trigger docs build when artifacts are published
- Add caching to docs-build
- Upgrade from 3.0.13 to 3.1.10 - SSL setup through jvm properties broken HOT 3
- JDK22 and GraalVM spring-boot:3.2.4:build-image failed: Builder lifecycle 'creator' failed with status code 51 HOT 1
- Graceful Shutdown behavior ambiguity in Reference Guide
- Clarify that all named properties must match for @ConditionalOnProperty to match HOT 2
- Getting 500 instead of 404 with integration tests when updating from Spring Boot 3.1.x to to 3.2.4 HOT 6
- Bump gradle/wrapper-validation-action from 2.1.1 to 2.1.2
- Bump gradle/wrapper-validation-action from 2.1.1 to 2.1.2
- Remove redundant Regex escapes
- Remove redundant Regex escapes
- Remove redundant Regex escapes
- Verify snapshots once they have been deployed
- Verify snapshots once they have been deployed
- Verify snapshots once they have been deployed
- Upgrade to Gradle Enterprise Conventions 0.0.16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.