Mahdi Shabani
Mahdi Shabani

Reputation: 90

How to exclude some @Configuration file in Spring?

I have some @Configuration file in my spring project and I would like to exclude some of them when spring is starting up. In fact, I have a property file which contains the spring start up scenarios. In some scenarios I want to exclude some Configuration file. In XML form, we had "context:exclude-filter" but I did not find what the equivalence is in annotation base Configuration ?

Could anyone show me the hope?

Upvotes: 1

Views: 2494

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328770

There are a couple of ways to do this:

  1. Configurations can import each other. So you can create a set of empty "top configurations" and then select one of them. Each imports only those configurations that you need.

  2. You can disable beans and configurations using the @Profile annotation.

  3. You can mix XML and Java style classes. Use as many Java style configs as possible and handle the few corner cases in XML.

With more recent versions of Spring, you can hook into the Profile system and add your own filters.

Upvotes: 3

Related Questions