SpringRunner ignores application properties

I am trying to create Spring integration tags as follows:

@RunWith(SpringRunner::class) @ActiveProfiles(profiles = ["Test"]) @ContextConfiguration(locations = ["classpath:**/applicationContext.xml"]) open class SimpleEntityIT {...} 

applicationContact.xml contains:

  <context:annotation-config/> <context:spring-configured/> <context:property-placeholder ignore-resource-not-found="false" location="classpath:application${spring.profiles.active}.properties,classpath:application.properties"/> <context:component-scan base-package="net.goout"/> 

The application file is loading, but it seems to be mostly ignored. Beans are not created using component scanning, and application.properties completely ignored, not mentioned in the logs:

  2018-01-26 20:09:26,131 DEBUG Resolved location pattern [classpath:**/applicationContext.xml] to resources [] 2018-01-26 20:09:26,132 DEBUG Loaded 0 bean definitions from location pattern [classpath:**/applicationContext.xml] 2018-01-26 20:09:26,167 INFO Refreshing org.springframework.context.support.GenericApplicationContext@ae cb35a: startup date [Fri Jan 26 20:09:26 CET 2018]; root of context hierarchy 2018-01-26 20:09:26,167 DEBUG Bean factory for org.springframework.context.support.GenericApplicationContext@ae cb35a: org.s pringframework.beans.factory.support.DefaultListableBeanFactory@ 20d3d15a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory]; root of factory hierarchy 2018-01-26 20:09:26,198 DEBUG Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 2018-01-26 20:09:26,198 DEBUG Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 2018-01-26 20:09:26,225 DEBUG Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references 2018-01-26 20:09:26,231 DEBUG Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' 

What am I not getting?

EDIT: Component scanning of Beans events has not been built, but in fact there are no Beans - even those defined by <bean> in applicationContext.xml. It seems that its contents are simply ignored, even if it is correctly found.

+7
spring spring-test junit
source share
2 answers

In accordance with recent comments, I believe that this problem has been solved, but even then a couple of quick observations and alternatives:

a) You did not receive an error with a missing resource due to the lower attr, I would suggest making it true in order to identify problems at an early stage:

ignore-resource-not-found = false

Alternatively, you can use below:

 @PropertySource(value = "xyz.properties", ignoreResourceNotFound = true) 

b) Completely unrelated, but:

 @ActiveProfiles(profiles = ["Test"]) 

It can be written as:

 @ActiveProfiles({"Test","QA"}) or in your application-test.properties spring.profiles.active=Test,QA 

c) To place applicationContext.xml, an alternative can also be placed in web.xml:

 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/spring/*.xml</param-value> </context-param> 

(Although, annotating the exact location with @ContextConfiguration is also fine!)

And first of all, if you are using annotation based configuration, I would recommend Spring boot :-)

Hope this helps!

+2
source share

You should not copy applicationContext.xml to / test / resources yourself. Allow it maven

 <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> </build> 
+1
source share

All Articles