SpringSource/spring-scala — pull request #9 by hekonsek (2013-02-25 08:27:57+00:00)
Title: Fixed BeanPostProcessor detection.

Hi,

While playing around with `FunctionalConfiguration` I've discovered that `BeanPostProcessor` instances registered in the context via `bean()` DSL method do not processes the beans as they ought to.

The minimal example of such broken configuration is demonstrated below.

class ConfigWithBeanPostProcessor extends FunctionalConfiguration {

bean()(new AutowiredAnnotationBeanPostProcessor)

bean()("autowireMe")

bean()(new AutowireSubject)

}

class AutowireSubject {

@Autowired
var autowiredMember : String = _

}

What we expect here is that String will be injected into the `AutowireSubject` as `autowiredMember`. Unfortunately it is not true.

I couldn't resist the temptation and investigated this problem a little bit. The issue is that `FunctionalConfiguration#bean` method registers the `Function0Wrapper` instance which is responsible for creating the actual `BeanPostProcessor` object. However `AbstractBeanFactory#isFactoryBean` method cannot recognize that `Function0Wrapper#apply` method returns `BeanPostProcessor` instance because the return type of the latter method is parameterized as `` (i.e. returns `Object` for the reflection API).

I definitely don't feel like Spring internals expert, but the solution that seems reasonable for me is to recognize on the `FunctionalGenericBeanDefinition` level if the wrapped function returns `BeanPostProcessor`. If so, then `FunctionalGenericBeanDefinition` should be created with the special version of `Function0Wrapper#apply` method called (let's say) `Function0Wrapper#applyAsBeanPostProcessor`. The latter factory method would wrap `Function0` instances and explicitly define `BeanPostProcessor` return type. If `Function0Wrapper` factory method defined on `FunctionalGenericBeanDefinition` has return type of `BeanPostProcessor`, then `AbstractBeanFactory#isFactoryBean` works like a charm. And `AbstractBeanFactory#isFactoryBean` method working properly resolves the issue, as `AbstractApplicationContext#registerBeanPostProcessors` can recognize that instance return by `Function0Wrapper` is a `BeanPostProcessor`.

The pull request contains both fix and test case for it.

Best regards.