Context:component-scan stopped working after move to Gradle

Gradle looks awesome and my first impression is great!

I have a web application that today is build with Maven but yesterday I decided to try Gradle.

Everything went smooth EXCEPT for the fact the scanning for entity beans has stopped working. In unit tests as well as in the web app.

I have stared at the dependencies listed by Gradle and the Maven listing in eclipse and can’t see any diffs.

But surely there must be something since no entity beans are found. The Spring annotations works it’s just the JPA ones that are not found or not scanned.

Does anyone have a clue how to find out what’s wrong!?

I have added the relevent parts of my Spring config below.


<context:annotation-config />
      <context:component-scan base-package="utskicket.jobs" />
     <context:component-scan base-package="utskicket.model.entity" />
    <context:component-scan base-package="utskicket.model.dao" />
    <context:component-scan base-package="utskicket.model.persistence" />
    <context:component-scan base-package="utskicket.services" />
      <bean id="project-properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders">
            <value>true</value>
        </property>
        <property name="locations">
            <list>
                <value>classpath*:config/${UTSKICKET_ENVIRONMENT}/database.properties</value>
                <value>classpath*:config/utskicket.properties</value>
            </list>
        </property>
    </bean>
      <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${hibernate.connection.driver_class}" />
        <property name="url" value="${hibernate.connection.url}" />
        <property name="username" value="${hibernate.connection.username}" />
        <property name="password" value="${hibernate.connection.password}" />
    </bean>
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="utskicketPersistence" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaDialect">
            <bean class="${jpa.dialect}" />
        </property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.${jpa.vendor.adapter}">
                <property name="showSql" value="${hibernate.show_sql}" />
                <property name="databasePlatform" value="${hibernate.dialect}" />
                <property name="generateDdl" value="false" />
            </bean>
        </property>
    </bean>
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
      <tx:annotation-driven transaction-manager="transactionManager" />

It’s hard to say without seeing the exact exception (that tells us the exact reason) and without understanding when exactly the exception occurs (at wiring time, at executing a method on the bean, etc?).

I suspect it’s a classpath issue, e.g. where do your resources live (e.g. config/utskicket.properties, etc.)? Are they under src/main/resources?

Also, your tests do not work when you run from the console or from the IDE?

The problem was solved by adding the entity classes to persistence.xml

I don’t know why it worked with Maven without having them there.