【发布时间】:2019-01-27 08:11:26
【问题描述】:
我正在尝试从ldap-TEST.properties 文件中读取 ldap 属性
并尝试将其绑定到我指定的 java config class.for
@PropertSource 并为 propertysourcesplaceholderconfigurer 定义了一个静态 Bean。
我仍然得到无法解析占位符spring.profiles.active in value classpath:/ldap-${spring.profiles.active}.properties 下面是项目文件,请帮助我
@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
我的主要应用程序
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
【问题讨论】:
-
你检查过 ${spring.profiles.active} 的值吗?
-
-Dspring.profiles.active=TEST 在启动应用程序时传递参数
-
@OresteViron in application.properties 我定义了 spring.profiles.active=TEST
-
@Abdul 我如何通过 -Dspring.profiles.active=TEST 我正在将我的应用程序部署到 jboss 我没有从命令行运行你能告诉我我在哪里可以提供参数
标签: java spring spring-boot application.properties