gpt4 book ai didi

spring - 启用 AOP 会破坏我对采用字符串的工厂 bean 的依赖注入(inject)

转载 作者:行者123 更新时间:2023-12-04 17:19:12 25 4
gpt4 key购买 nike

启用 AOP 会破坏我对采用字符串的工厂 bean 的依赖注入(inject)。

这是上下文文件中的片段:

<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();
}
}

这是个异常(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

最佳答案

看来,它与 @target切入点表达式中的指示符。我可以使用类似于您的简单设置来重现该行为(在切入点中只有一个自定义注释)。使用简单的 execution() 即可正常工作代号虽然。

不幸的是,我不知道为什么这会导致 Spring 代理 String 对象。

关于spring - 启用 AOP 会破坏我对采用字符串的工厂 bean 的依赖注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4850536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com