This tutorial shows how to assign Profiles to Classes by specifying for which
● Profile to include Class @Profile("Profile1")
● Profile to exclude Class @Profile("!Profile1")
● Profiles to include/exclude Class @Profile({"Profile1", "!Profile2"})
Classes for which Profile is not assigned are always included in the application.
Assigning Profile to a Class is used in combination with @Autowired on Interface to tell Spring which Class to instantiate.
Such usage is demonstrated in tutorial Interface - @Profile.
application.properties (specify active Profile)
spring.profiles.active = Profile1
MyServiceImplementation1.java (assign Profile to Class)
@Profile( "Profile1" )
@Profile({"Profile2","Profile3"})
public class MyServiceImplementation1 implements MyServiceInterface { ... }
MyController.java (instantiate included Implementation/Class)
@Autowired
MyServiceInterface myService;