mardi 10 mai 2016

Why Spring autowiring does not work with Spock?

Why Spring autowiring does not work with Spock?
Maybe, because of profile (it is used for baseDAO),
But profile looks good and this code works for JUnit well (same contexts).

Code

class CategoryDAOSpecification extends SpringSpecification {
    @Autowired
    @Qualifier("categoryDAO")
    private CategoryDAO testTarget//...
}
@ActiveProfiles("test")
@TestExecutionListeners([
    DependencyInjectionTestExecutionListener,
    DirtiesContextTestExecutionListener,
    TransactionalTestExecutionListener,
    DbUnitTestExecutionListener,
    HSqlTestExecutionListener
])
@ContextConfiguration(["classpath*:contexts/dao-beans.xml"])
class SpringHsqlSpecification extends Specification {//...
}

Context

<beans...>
<bean id="categoryDAO" class="com.opti.dao.sql.hibernate.CategoryDAO"
      scope="prototype" parent="baseDAO">
</bean>
</beans>

Profile

<beans...>
<beans profile="test">
    <context:property-placeholder properties-ref="properties" ignore-resource-not-found="false"/>
    <bean id="properties" lazy-init="false"
          class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:properties/test-database.properties</value>
            </list>
        </property>
    </bean>
</beans>
</beans>

Aucun commentaire:

Enregistrer un commentaire