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

  • BeanFactoryPostProcessor and @Transactional don't work together


    I have BeanFactoryPostProcessor to add additional beans definitions and add references to these beans to list, which is a property of a bean (providers).
    	<bean id="mainBean" class="com.example">
    		<property name="providers">
    				<ref bean="provider1" />
    The additional beans definitions are taken from database and next added to "mainBean":
    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")){
    		XmlBeanFactory xmlFactory = createDynamicXmlFactory(beanFactory, providersDefinitionBuffer);
    		List<ProviderInterface> configuredProviders = authenticationManager.getProviders();
    		for (String providerKey: providersDefinitionList) {
    			ProviderInterface provider = (ProviderInterface) xmlFactory.getBean(providerKey);
    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).


    • #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