Skip to content

Properly document the use of MVC Java config with multiple (independent) components contributing configuration [SPR-10565] #15195

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-10565 and commented

Assume you have to JavaConfig classes extending WebMvcConfigurationSupport, both overriding one of the callbacks of the parent class. Only the first one registered actually gets the callback invoked. See the following test case, the assertion fails with only one resolver registered.

@RunWith(MockitoJUnitRunner.class)
public class ConfigTest {

	@Mock
	static HandlerMethodArgumentResolver resolver;

	@Configuration
	static class FirstConfig extends WebMvcConfigurationSupport {

		@Override
		protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
			argumentResolvers.add(resolver);
		}
	}

	@Configuration
	static class SecondConfig extends WebMvcConfigurationSupport {

		@Override
		protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
			argumentResolvers.add(resolver);
		}
	}

	@Test
	public void foo() {

		AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
		context.setServletContext(new MockServletContext());
		context.register(FirstConfig.class);
		context.register(SecondConfig.class);
		context.refresh();

		RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
		assertThat(adapter.getCustomArgumentResolvers().size(), is(2));
	}
}

Affects: 3.2.2

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions