Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 2.15 KB

spring-how-to-add-custom-argument-resolver.md

File metadata and controls

38 lines (29 loc) · 2.15 KB

Spring - How to add a custom ArgumentResolver

The core ArgumentResolvers provided in the application may not cover all the use cases for argument resolution, and the framework has been built to allow for the consumers to provide their own resolver easily. See core-how-to-implement-custom-argument-resolver.md for more details about how to build an ArgumentResolver.

Prerequisites

Steps

  1. Build your ArgumentResolver by following the guide provided by core-how-to-implement-custom-argument-resolver.md.

  2. Add this bean in the Spring Context by annotating it with a @Component (or other equivalent annotation) or by providing it as a bean in a @Configuration class.

    @Configuration
    public class MyConfiguration {
    
        @Bean
        public ArgumentResolver userGroupArgumentResolver() {
            return new UserGroupArgumentResolver();
        }
    }

At this point the default ArgumentResolverService should contain this custom argument resolver, and it should be applied during execution of the framework. This is because all ArgumentResolver beans are including in the underlying service.