Skip to content

MethodParameter doesn't see parameter annotations if method is proxied [SPR-16294] #20841

@spring-projects-issues

Description

@spring-projects-issues

Artem Bilan opened SPR-16294 and commented

My use-case is like: we have a @Transactional service method with the @Header annotation on one of the parameter. When we perform this method via InvocableHandlerMethod we end up with the problem that @Header isn't visible and Framework attempts to fallback to the payload for this parameter.

The test-case to reproduce:

	@Test
	public void testProxyAndHeaderAnnotation() throws Exception {
		final AtomicReference<Object> payloadReference = new AtomicReference<>();
		final AtomicReference<UUID> idReference = new AtomicReference<>();

		class MyHandler {

			public void handle(@Header(MessageHeaders.ID) UUID id, @Payload Object payload) {
				idReference.set(id);
				payloadReference.set(payload);
			}

		}

		MyHandler service = new MyHandler();

		ProxyFactory proxyFactory = new ProxyFactory(service);

		service = (MyHandler) proxyFactory.getProxy(getClass().getClassLoader());

		DefaultMessageHandlerMethodFactory handlerMethodFactory = new DefaultMessageHandlerMethodFactory();
		handlerMethodFactory.afterPropertiesSet();

		Method method = ClassUtils.getMethod(service.getClass(), "handle", null);
		InvocableHandlerMethod handlerMethod = handlerMethodFactory.createInvocableHandlerMethod(service, method);

		GenericMessage<String> testMessage = new GenericMessage<>("foo");
		handlerMethod.invoke(testMessage);

		assertEquals(testMessage.getPayload(), payloadReference.get());
		assertEquals(testMessage.getHeaders().getId(), idReference.get());
	}

When we comment out getProxy() everything works well as expected.

Not sure what is wrong, but looks like when we try to get annotations from the method parameter on proxied method, we don't get them. I just followed the debug from the HeaderMethodArgumentResolver.supportsParameter().

See the related JIRA for more information: https://jira.spring.io/browse/INT-4367


Affects: 5.0.2

Issue Links:

  • INT-4367 Definition of service-activator in pojo-style does not work with annotaded parameters

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions