I'm trying to use an Enum to define the different profiles my Spring application might use.
This is my enum Profiles.java
public enum Profiles {
DEVELOPMENT("dev"),
TEST("test"),
PRODUCTION("prod");
private final String code;
private Profiles(String code) {
this.code = code;
}
}
I'm using it in a file to configure the properties place holders.
@Configuration
public class PropertyPlaceholderConfig {
@Profile(Profiles.DEVELOPMENT)
public static class DevelopmentConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("props/application-dev.properties"));
return propertySourcesPlaceholderConfigurer;
}
}
@Profile(Profiles.TEST)
public static class TestConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("props/application-test.properties"));
return propertySourcesPlaceholderConfigurer;
}
}
@Profile(Profiles.PRODUCTION)
public static class ProductionConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("application-test.properties"));
return propertySourcesPlaceholderConfigurer;
}
}
}
However it is complaining at @Profile that its getting incompatible types, got Profiles expected String. I feel like I'm missing something really silly.