Spring 启用AOP会中断我对接受字符串的工厂bean的依赖注入
启用AOP打破了我对接受字符串的工厂bean的依赖注入 以下是上下文文件中的片段:Spring 启用AOP会中断我对接受字符串的工厂bean的依赖注入,spring,spring-aop,Spring,Spring Aop,启用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'}"/>
<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>
这是个例外
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
不会无缘无故执行代理。可能您声明了某些方面,其切入点包括字符串,因此它已被代理。似乎它与切入点表达式中的@target
指示符有关。我可以通过与您类似的简单设置(在切入点中仅使用自定义注释)重现该行为。它可以与一个简单的execution()
指示符配合使用
不幸的是,我不知道为什么这会导致Spring代理String对象。我在原始问题中添加了唯一方面的细节。切入点不是指字符串。
@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