Konfigurieren von AspectJ-Aspekten mithilfe von Spring IoC mit JavaConfig?
Laut Spring's DocumentationKonfigurieren von Aspekten mit Spring IoC Um einen Aspekt für Spring IOC zu konfigurieren, muss der XML-Konfiguration Folgendes hinzugefügt werden:
<bean id="profiler" class="com.xyz.profiler.Profiler"
factory-method="aspectOf">
<property name="profilingStrategy" ref="jamonProfilingStrategy"/>
</bean>
Wie von @SotiriosDelimanolis vorgeschlagen, sollte das Umschreiben wie folgt in JavaConfig funktionieren:
@Bean
public com.xyz.profiler.Profiler profiler() {
com.xyz.profiler.Profiler profiler = com.xyz.profiler.Profiler.aspectOf();
profiler.setProfilingStrategy(jamonProfilingStrategy()); // assuming you have a corresponding @Bean method for that bean
return profiler;
}
Dies scheint jedoch nur zu funktionieren, wenn dieProfiler
aspect ist in native aspectj geschrieben.aj
Syntax. Wenn es in Java geschrieben und mit annotiert ist@Aspect
Ich erhalte folgende Fehlermeldung:
Die Methode aspectOf () ist für den Typ Profiler undefiniert
Gibt es eine äquivalente Möglichkeit, dies mit JavaConfig für Aspekte zu schreiben, die mit @AspectJ-Syntax geschrieben wurden?