Saurabh Valsangkar
Saurabh Valsangkar

Reputation: 99

How to exclude spring boot application beans from the test App context?

I am currently defining my Base specification as below:

@Configuration
@ActiveProfiles(profiles = "test")
@ContextConfiguration(locations = "classpath:test-config-context.xml" )
class SpringSharedSpecification extends Specification 

This also end up in processing my parent application-context.xml

I am using active profile option to not to load the main beans and execute with test-config I used below to skip application-context beans but doesn't feel it is the best way to do it. Can anyone suggest better way of skipping application-context.xml?

<beans profile="!test"> 

Thanks in advance for your answer.

Upvotes: 1

Views: 3114

Answers (1)

Max Farsikov
Max Farsikov

Reputation: 2763

You can use annotation on your bean class:

@Component
@Profile("!test")
class MyProductionBean {
}

Upvotes: 1

Related Questions