Announcement Announcement Module
Collapse
No announcement yet.
Java based configuration and EnableTransactionManagement Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java based configuration and EnableTransactionManagement

    I'm getting a rather odd exception that I donot think should be occuring.

    According to the documentation, @EnableTransactionManagement will look for a PlatformTransactionManager bean and find it automatically. However, with my configuration class, I get an exception. When I implement the TransactionManagementConfigurer interface the problem goes away.. but shouldn't @EnableTransactionManagement have found my PlatformTransactionManager Bean?

    Code:
    @Configuration
    @ComponentScan(basePackages = {"nl.stuff"})
    @EnableTransactionManagement
    public class ApplicationContext {
    
      @Bean
      public LocalPersistenceManagerFactoryBean localPersistenceManagerFactoryBean() {
        LocalPersistenceManagerFactoryBean bean = new LocalPersistenceManagerFactoryBean();
    
        bean.setJdoProperties(new Properties() {{
          put("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
          put("javax.jdo.option.ConnectionURL", "jdbc:derby:mappingsdb;create=true");
          put("datanucleus.autoCreateSchema", "true");
          put("javax.jdo.option.ConnectionDriverName", "org.apache.derby.jdbc.EmbeddedDriver");
        }});
    
        return bean;
      }
    
      @Bean
      public TransactionAwarePersistenceManagerFactoryProxy transactionAwarePersistenceManagerFactoryProxy() {
        TransactionAwarePersistenceManagerFactoryProxy proxy = new TransactionAwarePersistenceManagerFactoryProxy();
    
        proxy.setTargetPersistenceManagerFactory((PersistenceManagerFactory)localPersistenceManagerFactoryBean().getObject());
        proxy.setAllowCreate(false);
    
        return proxy;
      }
    
      @Bean
      public PlatformTransactionManager transactionManager() {
        JdoTransactionManager manager = new JdoTransactionManager();
    
        manager.setPersistenceManagerFactory((PersistenceManagerFactory)localPersistenceManagerFactoryBean().getObject());
    
        return manager;
      }
    }
    The exception is:

    Code:
    java.lang.IllegalStateException: Failed to load ApplicationContext
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    
    ... truncated due to post length ...
    
    	... 55 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionInterceptor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'transactionManager' is required
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:297)
    	at org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$80e2e79e.transactionInterceptor(<generated>)
    	at org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration.transactionAdvisor(ProxyTransactionManagementConfiguration.java:46)
    	at org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$80e2e79e.CGLIB$transactionAdvisor$0(<generated>)
    	at org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$80e2e79e$$FastClassByCGLIB$$265b6ace.invoke(<generated>)
    	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285)
    	at org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$80e2e79e.transactionAdvisor(<generated>)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
    	... 56 more
    Caused by: java.lang.IllegalArgumentException: Property 'transactionManager' is required
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.afterPropertiesSet(TransactionAspectSupport.java:195)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
    	... 75 more

  • #2

    I'm having the exact same problem. I'm using Spring 4. My configuration class is

    Code:
        @Configuration
        @Import(DaoConfig.class)
        @PropertySource("classpath:/jdbc.properties")
        @EnableTransactionManagement
        public static class TestConfig {
    
            @Bean
            public PlatformTransactionManager providesTransactionManager(ListableBeanFactory beanFactory) {
                return new DataSourceTransactionManager(beanFactory.getBean(DataSource.class));
            }
        }
    and the resulting exception is

    Code:
     Caused by: java.lang.IllegalArgumentException: Property 'transactionManager' is required
              at org.springframework.transaction.interceptor.TransactionAspectSupport.afterPropertiesSet(TransactionAspectSupport.java:195)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
              ... 82 more
    And, as you say, according to the javadoc, I should not have to name the transaction manager bean. It's the only bean of its type in the container, so it should be used.

    Anyone have any advice on this?

    Thanks.

    Comment


    • #3
      I have same problem. Please help me to solve this problem. I'm puzzled

      Comment

      Working...
      X