Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not resolve placeholder 'spring.profiles.active' in value "classpath:/ldap-${spring.profiles.active}.properties"

I am trying read ldap properties from a ldap-TEST.properties file and trying to bind it to a java config class.for that i had specified @PropertSource and defined a static Bean for propertysourcesplaceholderconfigurer. still i am getting the Could not resolve placeholder spring.profiles.active in value classpath:/ldap-${spring.profiles.active}.properties below are project files please help me

@Configuration
@PropertySource("classpath:/ldap-${spring.profiles.active}.properties")
public class LdapConfig { 
 @Autowired
 Environment env;
@Bean
public LdapContextSource contextSource() {
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl(env.getRequiredProperty("ldap.url"));
    contextSource.setBase(env.getRequiredProperty("ldap.base"));
    contextSource.setUserDn(env.getRequiredProperty("ldap.userDn"));
    contextSource.setPassword(env.getRequiredProperty("ldap.password"));
    contextSource.afterPropertiesSet();
    return contextSource;
}

@Bean
public LdapTemplate ldapTemplate() {
    return new LdapTemplate(contextSource());
}

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
}

}

//ldap-TEST.properties file
ldap.base=dc=example,dc=com
ldap.password=password
ldap.port=839
ldap.userDn=cn=read-only-admin,dc=example,dc=com
ldap.url=ldap://ldap.forumsys.com:389

my main application

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
       SpringApplication.run(Application.class, args);
 }

}

like image 386
user2307155 Avatar asked Nov 08 '22 03:11

user2307155


1 Answers

You can not use properties like ${spring.profiles.active} inside string value of Type annotation in spring. such properties would be injected into annotations like @Value which are for properties or methods.

like image 181
Mahdi Rajabi Avatar answered Nov 14 '22 22:11

Mahdi Rajabi