3

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>

これがファクトリービーンです。

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
4

2 に答える 2

1

@targetポイントカット式の指定子と関係があるようです。私はあなたと同じような簡単なセットアップで動作を再現できます(ポイントカットにカスタム注釈のみがあります)。ただし、単純なexecution()指定子でも問題なく動作します。

残念ながら、これによりSpringがStringオブジェクトをプロキシする理由がわかりません。

于 2011-01-31T16:38:21.393 に答える
0

<aop:aspectj-autoproxy/>理由なしにプロキシを実行しません。おそらく、ポイントカットにsが含まれているアスペクトを宣言しStringたため、プロキシされています。

于 2011-01-31T12:46:55.900 に答える