org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator Java Examples
The following examples show how to use
org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AspectJAutoProxyCreatorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() { ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); GenericApplicationContext childAc = new GenericApplicationContext(ac); // Create a child factory with a bean that should be woven RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().addPropertyValue(new PropertyValue("name", "Adrian")) .addPropertyValue(new PropertyValue("age", 34)); childAc.registerBeanDefinition("adrian2", bd); // Register the advisor auto proxy creator with subclass childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition( AnnotationAwareAspectJAutoProxyCreator.class)); childAc.refresh(); ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2"); //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian")); doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); }
Example #2
Source File: AspectJAutoProxyCreatorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() { ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); GenericApplicationContext childAc = new GenericApplicationContext(ac); // Create a child factory with a bean that should be woven RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().addPropertyValue(new PropertyValue("name", "Adrian")) .addPropertyValue(new PropertyValue("age", 34)); childAc.registerBeanDefinition("adrian2", bd); // Register the advisor auto proxy creator with subclass childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition( AnnotationAwareAspectJAutoProxyCreator.class)); childAc.refresh(); ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2"); //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian")); doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); }
Example #3
Source File: AspectJAutoProxyCreatorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() { ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); GenericApplicationContext childAc = new GenericApplicationContext(ac); // Create a child factory with a bean that should be woven RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().addPropertyValue(new PropertyValue("name", "Adrian")) .addPropertyValue(new PropertyValue("age", new Integer(34))); childAc.registerBeanDefinition("adrian2", bd); // Register the advisor auto proxy creator with subclass childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition( AnnotationAwareAspectJAutoProxyCreator.class)); childAc.refresh(); ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2"); //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian")); doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); }
Example #4
Source File: BeanMethodPolymorphismTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void beanMethodThroughAopProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Config.class); ctx.register(AnnotationAwareAspectJAutoProxyCreator.class); ctx.register(TestAdvisor.class); ctx.refresh(); ctx.getBean("testBean", TestBean.class); }
Example #5
Source File: PersistenceExceptionTranslationPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test @SuppressWarnings("resource") public void proxiesCorrectly() { GenericApplicationContext gac = new GenericApplicationContext(); gac.registerBeanDefinition("translator", new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class)); gac.registerBeanDefinition("notProxied", new RootBeanDefinition(RepositoryInterfaceImpl.class)); gac.registerBeanDefinition("proxied", new RootBeanDefinition(StereotypedRepositoryInterfaceImpl.class)); gac.registerBeanDefinition("classProxied", new RootBeanDefinition(RepositoryWithoutInterface.class)); gac.registerBeanDefinition("classProxiedAndAdvised", new RootBeanDefinition(RepositoryWithoutInterfaceAndOtherwiseAdvised.class)); gac.registerBeanDefinition("myTranslator", new RootBeanDefinition(MyPersistenceExceptionTranslator.class)); gac.registerBeanDefinition("proxyCreator", BeanDefinitionBuilder.rootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class). addPropertyValue("order", 50).getBeanDefinition()); gac.registerBeanDefinition("logger", new RootBeanDefinition(LogAllAspect.class)); gac.refresh(); RepositoryInterface shouldNotBeProxied = (RepositoryInterface) gac.getBean("notProxied"); assertFalse(AopUtils.isAopProxy(shouldNotBeProxied)); RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied"); assertTrue(AopUtils.isAopProxy(shouldBeProxied)); RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied"); assertTrue(AopUtils.isAopProxy(rwi)); checkWillTranslateExceptions(rwi); Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised"); assertTrue(AopUtils.isAopProxy(rwi2)); rwi2.additionalMethod(false); checkWillTranslateExceptions(rwi2); try { rwi2.additionalMethod(true); fail("Should have thrown DataAccessResourceFailureException"); } catch (DataAccessResourceFailureException ex) { assertEquals("my failure", ex.getMessage()); } }
Example #6
Source File: BeanMethodPolymorphismTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void beanMethodThroughAopProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Config.class); ctx.register(AnnotationAwareAspectJAutoProxyCreator.class); ctx.register(TestAdvisor.class); ctx.refresh(); ctx.getBean("testBean", TestBean.class); }
Example #7
Source File: PersistenceExceptionTranslationPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test @SuppressWarnings("resource") public void proxiesCorrectly() { GenericApplicationContext gac = new GenericApplicationContext(); gac.registerBeanDefinition("translator", new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class)); gac.registerBeanDefinition("notProxied", new RootBeanDefinition(RepositoryInterfaceImpl.class)); gac.registerBeanDefinition("proxied", new RootBeanDefinition(StereotypedRepositoryInterfaceImpl.class)); gac.registerBeanDefinition("classProxied", new RootBeanDefinition(RepositoryWithoutInterface.class)); gac.registerBeanDefinition("classProxiedAndAdvised", new RootBeanDefinition(RepositoryWithoutInterfaceAndOtherwiseAdvised.class)); gac.registerBeanDefinition("myTranslator", new RootBeanDefinition(MyPersistenceExceptionTranslator.class)); gac.registerBeanDefinition("proxyCreator", BeanDefinitionBuilder.rootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class). addPropertyValue("order", 50).getBeanDefinition()); gac.registerBeanDefinition("logger", new RootBeanDefinition(LogAllAspect.class)); gac.refresh(); RepositoryInterface shouldNotBeProxied = (RepositoryInterface) gac.getBean("notProxied"); assertFalse(AopUtils.isAopProxy(shouldNotBeProxied)); RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied"); assertTrue(AopUtils.isAopProxy(shouldBeProxied)); RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied"); assertTrue(AopUtils.isAopProxy(rwi)); checkWillTranslateExceptions(rwi); Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised"); assertTrue(AopUtils.isAopProxy(rwi2)); rwi2.additionalMethod(false); checkWillTranslateExceptions(rwi2); try { rwi2.additionalMethod(true); fail("Should have thrown DataAccessResourceFailureException"); } catch (DataAccessResourceFailureException ex) { assertEquals("my failure", ex.getMessage()); } }
Example #8
Source File: BeanMethodPolymorphismTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void beanMethodThroughAopProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Config.class); ctx.register(AnnotationAwareAspectJAutoProxyCreator.class); ctx.register(TestAdvisor.class); ctx.refresh(); ctx.getBean("testBean", TestBean.class); }
Example #9
Source File: PersistenceExceptionTranslationPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("resource") public void proxiesCorrectly() { GenericApplicationContext gac = new GenericApplicationContext(); gac.registerBeanDefinition("translator", new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class)); gac.registerBeanDefinition("notProxied", new RootBeanDefinition(RepositoryInterfaceImpl.class)); gac.registerBeanDefinition("proxied", new RootBeanDefinition(StereotypedRepositoryInterfaceImpl.class)); gac.registerBeanDefinition("classProxied", new RootBeanDefinition(RepositoryWithoutInterface.class)); gac.registerBeanDefinition("classProxiedAndAdvised", new RootBeanDefinition(RepositoryWithoutInterfaceAndOtherwiseAdvised.class)); gac.registerBeanDefinition("myTranslator", new RootBeanDefinition(MyPersistenceExceptionTranslator.class)); gac.registerBeanDefinition("proxyCreator", BeanDefinitionBuilder.rootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class). addPropertyValue("order", 50).getBeanDefinition()); gac.registerBeanDefinition("logger", new RootBeanDefinition(LogAllAspect.class)); gac.refresh(); RepositoryInterface shouldNotBeProxied = (RepositoryInterface) gac.getBean("notProxied"); assertFalse(AopUtils.isAopProxy(shouldNotBeProxied)); RepositoryInterface shouldBeProxied = (RepositoryInterface) gac.getBean("proxied"); assertTrue(AopUtils.isAopProxy(shouldBeProxied)); RepositoryWithoutInterface rwi = (RepositoryWithoutInterface) gac.getBean("classProxied"); assertTrue(AopUtils.isAopProxy(rwi)); checkWillTranslateExceptions(rwi); Additional rwi2 = (Additional) gac.getBean("classProxiedAndAdvised"); assertTrue(AopUtils.isAopProxy(rwi2)); rwi2.additionalMethod(false); checkWillTranslateExceptions(rwi2); try { rwi2.additionalMethod(true); fail("Should have thrown DataAccessResourceFailureException"); } catch (DataAccessResourceFailureException ex) { assertEquals("my failure", ex.getMessage()); } }
Example #10
Source File: AopConfigUtils.java From spring-analysis-note with MIT License | 4 votes |
@Nullable public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary( BeanDefinitionRegistry registry, @Nullable Object source) { // 实际注册的 bean 类型是 AnnotationAwareAspectJAutoProxyCreator return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); }
Example #11
Source File: ScheduledAndTransactionalAnnotationIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
@Bean public static AnnotationAwareAspectJAutoProxyCreator autoProxyCreator() { AnnotationAwareAspectJAutoProxyCreator apc = new AnnotationAwareAspectJAutoProxyCreator(); apc.setProxyTargetClass(true); return apc; }
Example #12
Source File: AopConfigUtils.java From java-technology-stack with MIT License | 4 votes |
@Nullable public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary( BeanDefinitionRegistry registry, @Nullable Object source) { return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); }
Example #13
Source File: ScheduledAndTransactionalAnnotationIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
@Bean public static AnnotationAwareAspectJAutoProxyCreator autoProxyCreator() { AnnotationAwareAspectJAutoProxyCreator apc = new AnnotationAwareAspectJAutoProxyCreator(); apc.setProxyTargetClass(true); return apc; }
Example #14
Source File: AopConfigUtils.java From lams with GNU General Public License v2.0 | 4 votes |
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) { return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); }
Example #15
Source File: AopConfigUtils.java From spring4-understanding with Apache License 2.0 | 4 votes |
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) { return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); }