Enabling AOP interrupts my dependency injection for a factory bean that takes a string

Turning on AOP interrupts my dependency injection for a factory bean that takes a string.

Here's a snippet from the context file:

<aop:aspectj-autoproxy/>

<bean id="foo"
      class="FooFactory"
      p:url-ref="url"/>

<bean id="url" class="java.lang.String">
    <constructor-arg value="#{ 'localhost:50131'}"/>
</bean>

Here is the factory bean.

public class FooFactory extends AbstractFactoryBean<Foo> {
    private String url;

    public void setUrl(final String url) {
        this.url = url;
    }

    @Override
    public Class<?> getObjectType() {
        return Foo.class;
    }

    @Override
    protected Foo createInstance() throws Exception {
        Validate.notNull(url, "null URL");
        return new FooFactory().createFoo(new String[]{url});
    }
}

Here are just the claimed aspect:

@Component
@Aspect
public class ProfilerAspect {
    @Around("@target(org.springframework.stereotype.Controller) && args(model,..)")
    public Object profileController(final ProceedingJoinPoint proceedingJoinPoint, final Model model) throws Throwable {
        return proceedingJoinPoint.proceed();
    }
}

And this is an exception

java.lang.IllegalStateException: Cannot convert value of type [$Proxy13 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [java.lang.String] for property 'url': no matching editors or conversion strategy found
+3
source share
2 answers

This seems to be related to the pointer @targetin the pointcut expression. I can reproduce the behavior with a simple setup similar to yours (only with custom annotation in pointcut). It works great with a simple pointer execution().

Unfortunately, I don't know why this forces Spring to proxy the String object.

+1
source

<aop:aspectj-autoproxy/> - . , - , pointcut String s, .

0

Source: https://habr.com/ru/post/1788965/


All Articles