-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Support method validation for an interface only proxy like an HTTP interface client #29782
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
Comments
Where does that Do you perhaps mean Spring's If so, have you registered an |
Thanks for the feedback. We'll look into it. |
The proxy advisors are not in the right order indeed. The one for Now So it looks like method validation via It's also interesting that it works with spring-cloud-openfeign. @DanielLiu1123, do you get an actual |
Here's my test example(Spring Boot 3.0.1, Spring Cloud 2022.0.0): dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
} @SpringBootApplication
@EnableFeignClients
public class App implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@FeignClient(name = "post", url = "https://my-json-server.typicode.com")
@Validated
interface FeignPostApi {
@GetMapping("/typicode/demo/posts/{id}")
Post get(@PathVariable("id") @Min(2) int id);
}
@HttpExchange("https://my-json-server.typicode.com")
@Validated
interface HttpExchangePostApi {
@GetExchange("/typicode/demo/posts/{id}")
Post get(@PathVariable("id") @Min(2) int id);
}
@Data
static class Post {
public String id;
public String title;
}
@Autowired
HttpExchangePostApi httpExchangePostApi;
@Autowired
FeignPostApi feignPostApi;
@Override
public void run(ApplicationArguments args) throws Exception {
// @Validated not work, can get the response
System.out.println(httpExchangePostApi.get(1));
// @Validated works, throw ConstraintViolationException
System.out.println(feignPostApi.get(1));
}
@Bean
public HttpExchangePostApi postApi(WebClient.Builder builder) {
return HttpServiceProxyFactory.builder(WebClientAdapter.forClient(builder.build()))
.build()
.createClient(HttpExchangePostApi.class);
}
}
|
I personally think the ability to support |
This has been addressed by improving Spring AOP support for interface-only proxies where there is no target class, and in which case the last AOP advisor does the actual work and should always remain last in the order. So this change should help not only method validation, but also any other AOP advice applied to an HTTP interface client. |
I want to validate the params on client side, it works fine when using
spring-cloud-openfeign
, but it doesn't work when usingHttpExchange
.The text was updated successfully, but these errors were encountered: