spring.profiles.active

This commit is contained in:
MaxKey
2021-03-26 11:35:36 +08:00
parent 290dd28077
commit 2d9df5b0b3
24 changed files with 660 additions and 425 deletions

View File

@@ -56,7 +56,6 @@ import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
@PropertySource(ConstantsProperties.maxKeyPropertySource)
public class ApplicationAutoConfiguration implements InitializingBean {
private static final Logger _logger =
LoggerFactory.getLogger(ApplicationAutoConfiguration.class);
@@ -76,19 +75,18 @@ public class ApplicationAutoConfiguration implements InitializingBean {
@Bean (name = "propertySourcesPlaceholderConfigurer")
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
throws IOException {
ClassPathResource classPathResource1 =
ClassPathResource classPathApplicationPropertySource =
new ClassPathResource(ConstantsProperties.classPathResource(
ConstantsProperties.applicationPropertySource));
ClassPathResource classPathResource2 =
new ClassPathResource(ConstantsProperties.classPathResource(
ConstantsProperties.maxKeyPropertySource));
PropertySourcesPlaceholderConfigurer configurer =
new PropertySourcesPlaceholderConfigurer();
configurer.setLocations(
configurer.setLocations(classPathApplicationPropertySource);
/*configurer.setLocations(
classPathResource1,
classPathResource2
);
);*/
configurer.setIgnoreUnresolvablePlaceholders(true);
_logger.debug("PropertySourcesPlaceholderConfigurer init");
return configurer;
@@ -150,9 +148,9 @@ public class ApplicationAutoConfiguration implements InitializingBean {
*/
@Bean(name = "keyStoreLoader")
public KeyStoreLoader keyStoreLoader(
@Value("${config.saml.v20.idp.issuing.entity.id}") String entityName,
@Value("${config.saml.v20.idp.keystore.password}") String keystorePassword,
@Value("${config.saml.v20.idp.keystore}") Resource keystoreFile) {
@Value("${maxkey.saml.v20.idp.issuing.entity.id}") String entityName,
@Value("${maxkey.saml.v20.idp.keystore.password}") String keystorePassword,
@Value("${maxkey.saml.v20.idp.keystore}") Resource keystoreFile) {
KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
keyStoreLoader.setEntityName(entityName);
keyStoreLoader.setKeystorePassword(keystorePassword);
@@ -166,9 +164,9 @@ public class ApplicationAutoConfiguration implements InitializingBean {
*/
@Bean(name = "spKeyStoreLoader")
public KeyStoreLoader spKeyStoreLoader(
@Value("${config.saml.v20.sp.issuing.entity.id}") String entityName,
@Value("${config.saml.v20.sp.keystore.password}") String keystorePassword,
@Value("${config.saml.v20.sp.keystore}") Resource keystoreFile) {
@Value("${maxkey.saml.v20.sp.issuing.entity.id}") String entityName,
@Value("${maxkey.saml.v20.sp.keystore.password}") String keystorePassword,
@Value("${maxkey.saml.v20.sp.keystore}") Resource keystoreFile) {
KeyStoreLoader keyStoreLoader = new KeyStoreLoader();
keyStoreLoader.setEntityName(entityName);
keyStoreLoader.setKeystorePassword(keystorePassword);
@@ -182,7 +180,7 @@ public class ApplicationAutoConfiguration implements InitializingBean {
*/
@Bean(name = "spIssuingEntityName")
public String spIssuingEntityName(
@Value("${config.saml.v20.sp.issuing.entity.id}") String spIssuingEntityName) {
@Value("${maxkey.saml.v20.sp.issuing.entity.id}") String spIssuingEntityName) {
return spIssuingEntityName;
}

View File

@@ -58,7 +58,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
@PropertySource(ConstantsProperties.maxKeyPropertySource)
public class MvcAutoConfiguration implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(MvcAutoConfiguration.class);
@@ -68,7 +67,7 @@ public class MvcAutoConfiguration implements InitializingBean {
*/
@Bean (name = "localeResolver")
public CookieLocaleResolver cookieLocaleResolver(
@Value("${config.server.domain:maxkey.top}")String domainName) {
@Value("${maxkey.server.domain:maxkey.top}")String domainName) {
_logger.debug("DomainName " + domainName);
CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
cookieLocaleResolver.setCookieName("maxkey_lang");

View File

@@ -36,7 +36,6 @@ import org.springframework.stereotype.Component;
*
*/
@Component
@PropertySource(ConstantsProperties.maxKeyPropertySource)
@PropertySource(ConstantsProperties.applicationPropertySource)
public class ApplicationConfig {
private static final Logger _logger = LoggerFactory.getLogger(ApplicationConfig.class);
@@ -50,22 +49,22 @@ public class ApplicationConfig {
@Autowired
LoginConfig loginConfig;
@Value("${config.server.basedomain}")
@Value("${maxkey.server.basedomain}")
String baseDomainName;
@Value("${config.server.domain}")
@Value("${maxkey.server.domain}")
String domainName;
@Value("${config.server.name}")
@Value("${maxkey.server.name}")
String serverName;
@Value("${config.server.uri}")
@Value("${maxkey.server.uri}")
String serverPrefix;
@Value("${config.server.default.uri}")
@Value("${maxkey.server.default.uri}")
String defaultUri;
@Value("${config.server.management.uri}")
@Value("${maxkey.server.management.uri}")
String managementUri;
@Value("${server.port:8080}")
@@ -74,10 +73,10 @@ public class ApplicationConfig {
@Value("${server.servlet.session.timeout:1800}")
private int sessionTimeout;
@Value("${config.identity.kafkasupport:false}")
@Value("${maxkey.identity.kafkasupport:false}")
private boolean kafkaSupport;
@Value("${config.maxkey.uri}")
@Value("${maxkey.maxkey.uri}")
private String maxKeyUri;
public int getPort() {

View File

@@ -23,31 +23,31 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(ConstantsProperties.maxKeyPropertySource)
@PropertySource(ConstantsProperties.applicationPropertySource)
public class LoginConfig {
@Value("${config.login.captcha}")
@Value("${maxkey.login.captcha}")
boolean captcha;
//验证码类型 text 文本 arithmetic算术验证码
@Value("${config.login.captcha.type:text}")
@Value("${maxkey.login.captcha.type:text}")
String captchaType;
@Value("${config.login.mfa}")
@Value("${maxkey.login.mfa}")
boolean mfa;
@Value("${config.login.socialsignon}")
@Value("${maxkey.login.socialsignon}")
boolean socialSignOn;
@Value("${config.login.kerberos}")
@Value("${maxkey.login.kerberos}")
boolean kerberos;
@Value("${config.login.remeberme}")
@Value("${maxkey.login.remeberme}")
boolean remeberMe;
@Value("${config.login.wsfederation}")
@Value("${maxkey.login.wsfederation}")
boolean wsFederation;
@Value("${config.login.default.uri}")
@Value("${maxkey.login.default.uri}")
String defaultUri;
/**

View File

@@ -24,9 +24,6 @@ public class ConstantsProperties {
public static final String applicationPropertySource =
"classpath:/application.properties";
public static final String maxKeyPropertySource =
"classpath:/maxkey.properties";
public static final String kaptchaPropertySource =
"classpath:/kaptcha.properties";
@@ -34,8 +31,16 @@ public class ConstantsProperties {
return propertySource.replaceAll("classpath:","");
}
public static String classPathResource(String propertySource,String active) {
if(active == null || active.equals("")) {
return propertySource.replaceAll("classpath:","");
}
return propertySource.replace(".", "-"+active+".").replaceAll("classpath:","");
}
@Test
public void classPathResourceTest() {
System.out.println(classPathResource(maxKeyPropertySource));
System.out.println(classPathResource(applicationPropertySource));
System.out.println(classPathResource(applicationPropertySource,"active"));
}
}