Announcement Announcement Module
Collapse
No announcement yet.
BeanFactoryPostProcessor and @Transactional don't work together Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanFactoryPostProcessor and @Transactional don't work together

    Hi,

    I have BeanFactoryPostProcessor to add additional beans definitions and add references to these beans to list, which is a property of a bean (providers).
    Code:
    	<bean id="mainBean" class="com.example">
    		<property name="providers">
    			<list>
    				<ref bean="provider1" />
    			</list>
    		</property>
    	</bean>
    The additional beans definitions are taken from database and next added to "mainBean":
    Code:
    ApplicationMetadataDAOInterface metaDataDAO = (ApplicationMetadataDAOInterface) beanFactory.getBean("applicationMetadataDAO");		
    		Map<String, String> applicationMetadata = metaDataDAO.getApplicationMetadata();
    		
    		MainBeanInterface mainBean = (MainBeanInterface) beanFactory.getBean("mainBean");		
    
    		StringBuffer providersDefinitionBuffer = new StringBuffer();
    		List<String> providersDefinitionList = new ArrayList<String>();
    		
    		/**
    		 * Extract all Authentication Provider definitions
    		 */
    		for (String metadataKey: applicationMetadata.keySet()) {			
    			if (metadataKey.startsWith("some_text")){
    				providersDefinitionBuffer.append(applicationMetadata.get(metadataKey));
    				providersDefinitionBuffer.append("\n");
    				providersDefinitionList.add(metadataKey);
    			}
    		}
    
    		XmlBeanFactory xmlFactory = createDynamicXmlFactory(beanFactory, providersDefinitionBuffer);
    		
    		List<ProviderInterface> configuredProviders = authenticationManager.getProviders();
    		
    		for (String providerKey: providersDefinitionList) {
    			ProviderInterface provider = (ProviderInterface) xmlFactory.getBean(providerKey);
    			configuredProviders.add(provider);
    		}
    		mainBean.setProviders(configuredProviders);
    And I'm using @Transactional annotation on "mainBean". I've enabled transaction management in spring configuration file (<tx:annotation-driven>). But I don't have transaction on "mainBean".

    Why transaction annotations are not processed? Please could you explain me what I've missed? Or maybe it is a better idea to add some additional elements to list than getting it from database and then using BeanFactoryPostProcessor?

    Thanks for all your help

  • #2
    I suggest a read of chapter 3 of the reference guide.

    Transactions (or proxies) are applied using BeanPostProcessors which execute AFTER BeanFactoryPostProcessors. What you are doing isn't going to work and basically this will also render your dao always transaction less (as it is eagerly initialized).

    Comment


    • #3
      Thank you again Marten.

      Caould you provide me the good way how to achieve what I want? It means extend list of providers and have transactions? The additional configuration (beans definitions) don't have to be in database. If it will be better to have additional xml file and import it somehow then ok. But the solution has to allowed different beans definitions set for different instances of application. It means application has to be configured.

      Thank you again for your responses and help

      Comment

      Working...
      X