eclipse-ee4j / eclipse-ee4j/jersey

SpringComponentProvider#bind() doesn't find Proxied beans

Open
#4,096 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

SpringComponentProvider#bind() method doesn't find proxied beans.

```
public boolean bind(Class component, Set> providerContracts) {

if (ctx == null) {
return false;
}

if(component.isAnnotationPresent(Component.class)) {
DynamicConfiguration c = Injections.getConfiguration(locator);
String[] beanNames = ctx.getBeanNamesForType(component);
if(beanNames == null || beanNames.length != 1) {
LOGGER.severe(LocalizationMessages.NONE_OR_MULTIPLE_BEANS_AVAILABLE(component));
return false;
}
String beanName = beanNames[0];

ServiceBindingBuilder bb = Injections.newFactoryBinder(new SpringComponentProvider.SpringManagedBeanFactory(ctx, locator, beanName));
bb.to(component);
Injections.addBinding(bb, c);
c.commit();

LOGGER.config(LocalizationMessages.BEAN_REGISTERED(beanName));
return true;
}
return false;
}
```

Preconditions:
- have Spring JAX-RS (REST) resource class which is implementing some interface
- initialize it as a Spring Component (put Component annotation at the class level)
- use proxy mechanism for that resource, e.g. use Cachable on some of the methods

SpringComponentProvider#bind() uses Spring's ListableBeanFactory#getBeanNamesForType(Class) method to identify Spring beans of the REST resources in the Spring context by a class object of the Spring Component marked class. But if the resource classes are initialized as JDK AOP Proxies in the context (e.g Spring needs to use AOP to provide the cache functionality) then the JDK proxy is just a facade for the interface, not the actual implementing class.

In my opinion, the Spring Components should be found regardless whether they are Proxies - the result of the binding should be the same as if they are not.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.