Announcement Announcement Module
No announcement yet.
Advised bean no longer returned via getBeansOfType Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • philsttr
    started a topic Advised bean no longer returned via getBeansOfType

    Advised bean no longer returned via getBeansOfType

    I have a singleton bean like this:

    public class MyBean {
        public void myMethod();
    I retrieve it in several places like this:

    This works great. (Also it is autowired by type in several places)

    So, now I have advised the myMethod() method using Spring AOP (aspectj).

    Now, when the bean is instantiated, a proxy object is created as expected.

    However, this causes getBeansOfType(MyBean.class) to not return my bean.

    I've traced through Spring's code and found this:

    getBeansOfType eventually calls AbstractBeanFactory.isTypeMatch, which looks like this:

    public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
        String beanName = transformedBeanName(name);
        Class typeToMatch = (targetType != null ? targetType : Object.class);
        // Check manually registered singletons.
        Object beanInstance = getSingleton(beanName);
        if (beanInstance != null) {
            if (beanInstance instanceof FactoryBean) {
                ... snip ...
            else {
                return !BeanFactoryUtils.isFactoryDereference(name) &&
        ... snip ...
    The problem is that typeToMatch.isAssignableFrom(beanInstance.getClass ()); returns false. (MyBean.class.isAssignableFrom(proxyObject.getClas s()) is false)

    Is this a bug, or am I not doing something correctly?

  • philsttr
    From tracing through the code, I found that I needed to set ProxyConfig.proxyTargetClass to true (which will allow cglib proxies for classes). Now I just have to figure out how/where to set that property

    Leave a comment: