I am trying to prevent my spring boot application to start if I consider two or more active profiles to be conflicting. I.e. dev
and prod
should not be active at the same time.
Moreover, I want to make sure this logic and its integration into Spring bootstrapping code is properly tested.
I tried EnvironmentPostProcessor
as well as ApplicationEvent<ApplicationEnvironmentPrepared>
, I have annotated the test with @SpringBootTest
and I use assertThrows
in the test method.
If I do new AnnotationApplicationContext()
I don’t seem to find a way to manipulate the environment used by the context and if I try to SpringApplication.run()
a test application myself, it doesn’t seem to be able to find any injectable bean for environment at all.
I am pretty sure I am trying the wrong things and maybe there’s an easier way to achieve my goal anyway. Any hints or pointers would be greatly appreciated.
Jan von Löwenstein is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.