启用 AOP 会破坏我对采用字符串的工厂 bean 的依赖注入。
这是上下文文件中的片段:
<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>
这是工厂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});
}
}
这是唯一声明的方面:
@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();
}
}
这是个例外
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