我正在学习Introductions(在AspectJ中称为类型间声明)。我从使用XML的AspectJ的SpringAOP简介中得到了一个示例。我正在尝试使用注释复制相同内容,但我不知道如何进行。我在互联网上做了很多研究,但找不到任何样本。你能帮我这个忙吗?PerformanceTest.class@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = ConcertConfig.class)public class PerformanceTest { @Autowired public Audience audience; @Autowired public Performance liveOpera; @Autowired public EncoreableIntroducer encoreable; @Test public void testPerformance(){ liveOpera.perform(); }}LiveOpera.classpublic class LiveOpera implements Performance{ @Override public void perform() { System.out.println("Live Opera Performance Started"); }}Encoreable.interfacepublic interface Encoreable { public void performEncore();}DefaultEncoreable.classpublic class DefaultEncoreable implements Encoreable { @Override public void performEncore() { System.out.println("WoW!! What an encore performance!!"); }}ConcertConfig.class@Configuration@EnableAspectJAutoProxy@ComponentScanpublic class ConcertConfig { @Bean public Audience audience(){ return new Audience(); } @Bean public LiveOpera opera(){ return new LiveOpera(); } @Bean public EncoreableIntroducer encoreable(){ return new EncoreableIntroducer(); }}性能界面public interface Performance { public void perform();}EncoreableIntroducer.class@Aspectpublic class EncoreableIntroducer { @DeclareParents(value="com.example.introduction.Performance+", defaultImpl=DefaultEncoreable.class) public static Encoreable encoreable;}请让我知道,如何使用AspectJ-Introductions使用EncoreableIntroducer.class中的方面,以便可以使用DefaultEncoreable.class中的perform()方法?
添加回答
举报
0/150
提交
取消