Details
Description
When I add @EnableAspectJAutoProxy in my spring setup, with the bundled steps factory, my step beans can't be found.
I've done my own steps factory... it assumes the use of a specific type annotation on the step classes, to make it more clear which beans to explore, but that can be removed in a more general case.
Here it's how it looks like (WIP):
public class EnhancedSpringStepFactory extends AbstractStepsFactory { private static final Logger LOGGER = LoggerFactory .getLogger(EnhancedSpringStepFactory.class); private final ApplicationContext context; public EnhancedSpringStepFactory(ApplicationContext context, Configuration config) { super(config); this.context = context; } @Override public Object createInstanceOfType(Class<?> type) { return context.getBean(type); } @Override protected List<Class<?>> stepsTypes() { Set<Class<?>> result = new HashSet<>(); Map<String, Object> beans = context.getBeansWithAnnotation(Steps.class); for (Map.Entry<String, Object> kv : beans.entrySet()) { LOGGER.info("Possible candidate step class found in bean {}", kv.getKey()); final Class<?> target; if (AopUtils.isAopProxy(kv.getValue())) { LOGGER.info("Bean {} is an AOP proxy", kv.getKey()); target = AopProxyUtils.ultimateTargetClass(kv.getValue()); LOGGER.info("Extracted class name {} from bean {}", target.getName(), kv.getKey()); } else { LOGGER.info( "Bean {} is directly of type {} (not AOP enveloped)", kv.getKey(), kv.getValue().getClass().getName()); target = kv.getValue().getClass(); } if (hasAnnotatedMethods(target)) { if (!result.add(target)) { // TODO log sth... scoped } } else { LOGGER.warn( "Bean {} did not contain any JBehave annotated methods", kv.getKey()); } } return new LinkedList<>(result); } }
In my case it seems to work. I assume that, by returning the underlying target type in the stepTypes() method and not the proxy type, the matching logic of JBehave should work out of the box...
Do you foresee any problem with this kind of approach? if no, I can try a pull-request ...
Activity
Mauro Talevi
made changes -
Field | Original Value | New Value |
---|---|---|
Affects Version/s | 4.0 [ 18486 ] |
Mauro Talevi
made changes -
Resolution | Fixed [ 1 ] | |
Fix Version/s | 3.9.5 [ 20598 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |
I see no reason to have a separate factory. AOP support could be added to the existing SpringStepsFactory.
We can make it optional via a flag which is injected in the constructor.
If you could provide a pull request with the appropriate changes, and a test case to verify it's functionality, it'd be greatly appreciated.