I am trying to understand how to use @profiles in spring-batch. I created a java file with two classes in it:
@Configuration
@Profile("nonlocal")
class NonLocalConfiguration {
}
and
@Configuration
@Profile("local")
class LocalConfiguration {
}
in the main java class I am trying to set the profiles as follows:
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml");
String run_env = System.getenv("profile");
System.out.println("run_env is: " + run_env);
context.getEnvironment().setActiveProfiles(run_env);
context.refresh();
I set the profile using an Environment variable as profile=local
When the program is executed, I get a null pointer exception which I think is not getting the profile correctly. How can I use profiles concept in Spring Batch? Will it be different in normal spring vs spring batch?