Java Code Examples for org.springframework.aop.config.AopNamespaceUtils#registerAutoProxyCreatorIfNecessary()
The following examples show how to use
org.springframework.aop.config.AopNamespaceUtils#registerAutoProxyCreatorIfNecessary() .
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: AnnotationDrivenBeanDefinitionParser.java From JGiven with Apache License 2.0 | 6 votes |
@Override public BeanDefinition parse( Element element, ParserContext parserContext ) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary( parserContext, element ); if( !parserContext.getRegistry().containsBeanDefinition( BEAN_NAME ) ) { Object eleSource = parserContext.extractSource( element ); RootBeanDefinition stageCreator = new RootBeanDefinition( SpringStageCreator.class ); stageCreator.setSource( eleSource ); stageCreator.setRole( BeanDefinition.ROLE_INFRASTRUCTURE ); String executorName = parserContext.getReaderContext().registerWithGeneratedName( stageCreator ); logger.debug( "Registered SpringStageCreator with name " + executorName ); RootBeanDefinition beanFactoryPostProcessor = new RootBeanDefinition( JGivenBeanFactoryPostProcessor.class ); beanFactoryPostProcessor.setRole( BeanDefinition.ROLE_INFRASTRUCTURE ); parserContext.getRegistry().registerBeanDefinition( BEAN_NAME, beanFactoryPostProcessor ); CompositeComponentDefinition componentDefinition = new CompositeComponentDefinition( element.getTagName(), eleSource ); componentDefinition.addNestedComponent( new BeanComponentDefinition( stageCreator, executorName ) ); componentDefinition.addNestedComponent( new BeanComponentDefinition( beanFactoryPostProcessor, BEAN_NAME ) ); parserContext.registerComponent( componentDefinition ); } return null; }
Example 2
Source File: AnnotationDrivenBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME; if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) { Object eleSource = parserContext.extractSource(element); // Create the TransactionAttributeSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition( "org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the TransactionInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registerTransactionManager(element, interceptorDef); interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the TransactionAttributeSourceAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName)); parserContext.registerComponent(compositeDef); } }
Example 3
Source File: AnnotationDrivenBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME; if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) { Object eleSource = parserContext.extractSource(element); // Create the TransactionAttributeSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition( "org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the TransactionInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registerTransactionManager(element, interceptorDef); interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the TransactionAttributeSourceAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName)); parserContext.registerComponent(compositeDef); } }
Example 4
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void registerCacheAdvisor(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); SpringCachingConfigurer.registerCacheAdvisor(element, parserContext); if (jsr107Present && jCacheImplPresent) { // Register JCache advisor JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext); } }
Example 5
Source File: AspectJNamespaceHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("Incorrect APC class", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 6
Source File: AspectJNamespaceHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("APC class not switched", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 7
Source File: AspectJNamespaceHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRegisterAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); }
Example 8
Source File: CacheAnnotationParser.java From jetcache with Apache License 2.0 | 5 votes |
private synchronized void doParse(Element element, ParserContext parserContext) { String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute("base-package"), ",; \t\n"); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); if (!parserContext.getRegistry().containsBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); RootBeanDefinition configMapDef = new RootBeanDefinition(ConfigMap.class); configMapDef.setSource(eleSource); configMapDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String configMapName = parserContext.getReaderContext().registerWithGeneratedName(configMapDef); RootBeanDefinition interceptorDef = new RootBeanDefinition(JetCacheInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); interceptorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName))); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); RootBeanDefinition advisorDef = new RootBeanDefinition(CacheAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("adviceBeanName", interceptorName)); advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName))); advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("basePackages", basePackages)); parserContext.getRegistry().registerBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(configMapDef, configMapName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheAdvisor.CACHE_ADVISOR_BEAN_NAME)); parserContext.registerComponent(compositeDef); } }
Example 9
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private void registerCacheAdvisor(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); SpringCachingConfigurer.registerCacheAdvisor(element, parserContext); if (jsr107Present && jcacheImplPresent) { JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext); } }
Example 10
Source File: AnnotationDrivenBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME; if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) { Object eleSource = parserContext.extractSource(element); // Create the TransactionAttributeSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition( "org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the TransactionInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registerTransactionManager(element, interceptorDef); interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the TransactionAttributeSourceAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName)); parserContext.registerComponent(compositeDef); } }
Example 11
Source File: AspectJNamespaceHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRegisterAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); }
Example 12
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private void registerCacheAdvisor(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); SpringCachingConfigurer.registerCacheAdvisor(element, parserContext); if (jsr107Present && jcacheImplPresent) { JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext); } }
Example 13
Source File: AspectJNamespaceHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("Incorrect APC class", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 14
Source File: AspectJNamespaceHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("APC class not switched", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 15
Source File: AspectJNamespaceHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRegisterAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount()); }
Example 16
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private void registerCacheAdvisor(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); SpringCachingConfigurer.registerCacheAdvisor(element, parserContext); if (jsr107Present && jcacheImplPresent) { JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext); } }
Example 17
Source File: AspectJNamespaceHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception { AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("Incorrect APC class", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 18
Source File: AspectJNamespaceHandlerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals(1, registry.getBeanDefinitionCount()); AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null); assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount()); BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); assertEquals("APC class not switched", AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName()); }
Example 19
Source File: AnnotationDrivenBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) { // 注册 InfrastructureAdvisorAutoProxyCreator 自动创建代理器 AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); // txAdvisorBeanName = org.springframework.transaction.config.internalTransactionAdvisor String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME; if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) { Object eleSource = parserContext.extractSource(element); // Create the TransactionAttributeSource definition. // 创建 TransactionAttributeSource 的 bean RootBeanDefinition sourceDef = new RootBeanDefinition( "org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); // 注册 bean,并使用 Spring 中的定义规则生成 beanName String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the TransactionInterceptor definition. // 创建 TransactionInterceptor 的 bean RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); registerTransactionManager(element, interceptorDef); interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the TransactionAttributeSourceAdvisor definition. // 创建 TransactionAttributeSourceAdvisor 的 bean RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); // 将 sourceName 的 bean 注入 advisor 的 transactionAttributeSource 属性中 advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName)); // 将 interceptorName 的 bean 注入到 advisor 的 adviceBeanName 属性中 advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { // 如果配置了 order 属性,则加入到 bean 中 advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } // 以 txAdvisorBeanName 名字注册 advisorDef parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef); // 创建 CompositeComponentDefinition CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName)); parserContext.registerComponent(compositeDef); } }