lundi 28 septembre 2015

Applying multiple Spring profiles to a single Configuration class

I have 4 possible Spring profiles for my application

  • TEST (This is for Unit/Integration testing)
  • QA
  • STAGE
  • PRODUCTION

The last 3 in the above list are actutal environments in which this application will run.

Here's the overview of my configuration class called AppConfig

@Configuration
@ComponentScan(basePackages={"org.mycompany.services","org.mycompany.domain", "org.mycompany.utils"})
public class AppContext {

}

Here's my question: I want the AppContext's configuration to be applied for QA, STAGE and PRODUCTION profiles only (But not for TEST profile). What's the best way to do that?

The reason for this is that the above config class scans & picks classes from org.mycompany.services. But I do not want this package to be picked up for TEST profile as I'm intending to mock the classes in this package using Mockito.

Another possible question is if I need to rethink the way I'm approaching Unit/Integration testing so that I can simplify mocking of classes in org.mycompany.service package?

Aucun commentaire:

Enregistrer un commentaire