45

I'm having a lot of trouble to set up a configuration of Spring + Spring Data JPA + QueryDSL + JPA 2.0 + Hibernate in Maven. I already solved a lot of problems, but this one is giving me headache =/.

I'm getting the following exception:

Bean 'dataSource' of type [class org.springframework.jdbc.datasource.DriverManagerDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

I took a look in Google and most of times this problem is caused by the absence of the annotation "@Transactional". I tried to annotate my methods, but it didn't solve anything. I have absolutelly no idea about where it comes from =(.

Here's the code of my test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/applicationContext.xml")
public class BaseTest {

    public BaseTest() {
    }

    @Before
    public void setUp() throws IOException {
        Dataset.loadDatabase();
    }

    @Test
    public void load(){}
}

The class DataSet just do some saves in the db to see if it's working.

My ApplicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/data/jpa
       http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

        <context:annotation-config/>
        <jpa:repositories base-package="com.ae.repository" />
        <context:component-scan base-package="com.ae.service" />

        <!-- Data Source -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
            <property name="url"><value>jdbc:mysql://localhost:3306/academia</value></property>
            <property name="username"><value>root</value></property>
            <property name="password"><value>root</value></property>
        </bean>

        <!-- JPA EntityManagerFactory -->  
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">  
            <property name="dataSource" ref="dataSource"/>  
            <property name="jpaProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
                    <prop key="hibernate.id.new_generator_mappings">true</prop>
                </props>
            </property>
        </bean>  

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">  
            <property name="entityManagerFactory" ref="entityManagerFactory"/>  
        </bean> 
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>   
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>  
</beans>

I'm not sure if my dependencies are correctly set either:

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

        <!-- hibernate + jpa -->
        <dependency>  
            <groupId>org.hibernate</groupId>  
            <artifactId>hibernate-entitymanager</artifactId>  
            <version>4.1.6.Final</version>
        </dependency>  
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-log4j12</artifactId>  
            <version>1.6.6</version>  
        </dependency> 
        <dependency>  
            <groupId>org.apache.derby</groupId>  
            <artifactId>derby</artifactId>  
            <version>10.3.2.1</version>  
            <scope>test</scope>  
        </dependency>

        <!-- Spring JPA -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.sql</groupId>
            <artifactId>jdbc-stdext</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- MySQL Connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

        <!-- Query DSL -->
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>2.7.2</version>
            <scope>provided</scope>
        </dependency>    

        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>2.7.2</version>
        </dependency>

        <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>

        <!-- Apache commons lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <!-- Apache commons IO -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

        <!-- Other -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.1.2.RELEASE</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
    </dependencies>

Thank you for reading ;)

Tiago Peres França
  • 3,056
  • 2
  • 21
  • 23
  • 1
    You are getting that as an *exception*? Or do you mean as a log message? – Raedwald Jul 19 '13 at 09:59
  • See also http://stackoverflow.com/questions/1201726/tracking-down-cause-of-springs-not-eligible-for-auto-proxying/19688634#19688634 if you get "Bean is not eligible for getting processed by all BeanPostProcessors" – Aaron Digulla Oct 30 '13 at 17:11

1 Answers1

39

This warning means nothing, you shouldn't worry about it since you don't need to apply any post-processors to the DataSource.

Technically it means that some bean post-processor (a transactional one, I guess) depends on your DataSource, therefore the DataSource must be fully initialized before initialization of that post-processor, so that the post-processor cannot intercept initialization of the DataSource.

You need to worry if you get such a warning about a bean you want to apply post-processors to.

axtavt
  • 239,438
  • 41
  • 511
  • 482
  • Thank you for the answer axtavt! Reading the rest of the log I see that after trying to load the Dataset, for some reason, instead of using the information provided in the Dataset it tries to find a Persistence Unit File (persistence.xml under META-INF). If there's no persistence.xml the test fails saying no persistence unit was found. If I repeat the information given in the dataset bean in the persistence.xml it works fine, my database is successfully created. But now I have another problem: – Tiago Peres França Sep 11 '12 at 17:24
  • "Error creating bean with name 'albumServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ae.repository.AlbumRepository com.ae.service.impl.AlbumServiceImpl.albumRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'albumRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.ae.entity.Album". – Tiago Peres França Sep 11 '12 at 17:32
  • Google says it happens when you have an abstract class or an interface as an entity, but it's not my case. BTW, I get that same other error (not eligible for getting processed by all BeanPostProcessors) in my bean EntityManagerFactory, I'll igonore it. I'm gonna create another question concerning this "Not a managed type" problem, maybe it has nothing to do with the "not eligible for getting processed by all BeanPostProcessors" issue. Thanks ;) – Tiago Peres França Sep 11 '12 at 17:33
  • Well, it's weird... If I explicitly declare the class com.ae.Album in my persistence.xml it works. I'm gonna declare all my entities in the xml file instead of just annotating, I guess it will work. – Tiago Peres França Sep 11 '12 at 17:38