Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use argument-resolvers using annotation in Spring boot?

I would like to use argument-resolvers in Spring boot. How do I go about it? It is done in XML as below.

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <bean class="nl.t42.spring31.ValidatingRequestBodyMethodArgumentResolver"/>
    </mvc:argument-resolvers>
</mvc:annotation-driven>
like image 780
user1889970 Avatar asked Dec 14 '22 15:12

user1889970


1 Answers

See here

You can do:

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
      // equivalent to <mvc:argument-resolvers>
  }


  @Override
  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
      // equivalent to <mvc:message-converters>
  }
}

@EnableWebMvc will override the Boot defaults, you may want to skip it.

like image 62
Evgeni Dimitrov Avatar answered Jan 15 '23 02:01

Evgeni Dimitrov