springcloud &springcloud alibaba & nacos support

springcloud &springcloud alibaba & nacos support
This commit is contained in:
Crystal.Sea
2021-08-31 16:01:02 +08:00
parent 69b4c49aa2
commit 885dd27e6e
42 changed files with 224 additions and 228 deletions

View File

@@ -59,7 +59,6 @@ import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class ApplicationAutoConfiguration implements InitializingBean {
private static final Logger _logger =
LoggerFactory.getLogger(ApplicationAutoConfiguration.class);
@@ -76,7 +75,7 @@ public class ApplicationAutoConfiguration implements InitializingBean {
* @return propertySourcesPlaceholderConfigurer
* @throws IOException null
*/
@Bean (name = "propertySourcesPlaceholderConfigurer")
/*@Bean (name = "propertySourcesPlaceholderConfigurer")
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
throws IOException {
ClassPathResource classPathApplicationPropertySource =
@@ -105,7 +104,7 @@ public class ApplicationAutoConfiguration implements InitializingBean {
properties.load(resource.getInputStream());
return properties;
}
*/
@Bean(name = "passwordReciprocal")
public PasswordReciprocal passwordReciprocal() {

View File

@@ -23,7 +23,6 @@ import java.util.List;
import javax.servlet.Filter;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.constants.ConstantsTimeInterval;
import org.maxkey.persistence.db.LoginHistoryService;
import org.maxkey.persistence.db.LoginService;
@@ -41,7 +40,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -61,7 +60,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class MvcAutoConfiguration implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(MvcAutoConfiguration.class);
@@ -69,12 +67,13 @@ public class MvcAutoConfiguration implements InitializingBean {
* cookieLocaleResolver .
* @return cookieLocaleResolver
*/
@Primary
@Bean (name = "localeResolver")
public CookieLocaleResolver cookieLocaleResolver(
@Value("${maxkey.server.domain:maxkey.top}")String domainName) {
_logger.debug("DomainName " + domainName);
CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
cookieLocaleResolver.setCookieName("maxkey_lang");
cookieLocaleResolver.setCookieName("maxkey_locale");
cookieLocaleResolver.setCookieDomain(domainName);
cookieLocaleResolver.setCookieMaxAge(ConstantsTimeInterval.TWO_WEEK);
return cookieLocaleResolver;

View File

@@ -17,7 +17,6 @@
package org.maxkey.autoconfigure;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,11 +24,9 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class RedisAutoConfiguration implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(RedisAutoConfiguration.class);

View File

@@ -17,7 +17,6 @@
package org.maxkey.autoconfigure;
import org.maxkey.constants.ConstantsProperties;
import org.maxkey.persistence.redis.RedisConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,7 +25,6 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
@@ -34,7 +32,6 @@ import org.springframework.session.web.http.DefaultCookieSerializer;
@Configuration
@ConditionalOnProperty(value = "spring.session.store-type", havingValue = "redis", matchIfMissing = false)
@EnableRedisHttpSession
@PropertySource(ConstantsProperties.applicationPropertySource)
public class SessionRedisAutoConfiguration implements InitializingBean {
private static final Logger _logger = LoggerFactory.getLogger(SessionRedisAutoConfiguration.class);

View File

@@ -17,12 +17,11 @@
package org.maxkey.configuration;
import org.maxkey.constants.ConstantsProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/**
@@ -36,7 +35,7 @@ import org.springframework.stereotype.Component;
*
*/
@Component
@PropertySource(ConstantsProperties.applicationPropertySource)
@Configuration
public class ApplicationConfig {
private static final Logger _logger = LoggerFactory.getLogger(ApplicationConfig.class);
@@ -64,8 +63,11 @@ public class ApplicationConfig {
@Value("${maxkey.server.default.uri}")
String defaultUri;
@Value("${maxkey.server.management.uri}")
String managementUri;
@Value("${maxkey.server.mgt.uri}")
String mgtUri;
@Value("${maxkey.server.authz.uri}")
private String authzUri;
@Value("${server.port:8080}")
private int port;
@@ -76,9 +78,6 @@ public class ApplicationConfig {
@Value("${maxkey.identity.kafkasupport:false}")
private boolean kafkaSupport;
@Value("${maxkey.maxkey.uri}")
private String maxKeyUri;
@Value("${maxkey.notices.visible:false}")
private boolean noticesVisible;
@@ -170,13 +169,7 @@ public class ApplicationConfig {
this.emailConfig = emailConfig;
}
public String getManagementUri() {
return managementUri;
}
public void setManagementUri(String managementUri) {
this.managementUri = managementUri;
}
public String getDefaultUri() {
return defaultUri;
@@ -194,15 +187,23 @@ public class ApplicationConfig {
this.kafkaSupport = kafkaSupport;
}
public String getMaxKeyUri() {
return maxKeyUri;
}
public String getMgtUri() {
return mgtUri;
}
public void setMaxKeyUri(String maxKeyUri) {
this.maxKeyUri = maxKeyUri;
}
public void setMgtUri(String mgtUri) {
this.mgtUri = mgtUri;
}
public int getSessionTimeout() {
public String getAuthzUri() {
return authzUri;
}
public void setAuthzUri(String authzUri) {
this.authzUri = authzUri;
}
public int getSessionTimeout() {
return sessionTimeout;
}
@@ -238,13 +239,13 @@ public class ApplicationConfig {
builder.append(", defaultUri=");
builder.append(defaultUri);
builder.append(", managementUri=");
builder.append(managementUri);
builder.append(mgtUri);
builder.append(", port=");
builder.append(port);
builder.append(", kafkaSupport=");
builder.append(kafkaSupport);
builder.append(", maxKeyUri=");
builder.append(maxKeyUri);
builder.append(authzUri);
builder.append("]");
return builder.toString();
}

View File

@@ -19,10 +19,8 @@ package org.maxkey.configuration;
import java.io.UnsupportedEncodingException;
import org.maxkey.constants.ConstantsProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* 字符集转换及转换配置.
@@ -31,7 +29,6 @@ import org.springframework.context.annotation.PropertySource;
*
*/
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class CharacterEncodingConfig {
/**

View File

@@ -17,13 +17,10 @@
package org.maxkey.configuration;
import org.maxkey.constants.ConstantsProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class EmailConfig {
@Value("${spring.mail.username}")

View File

@@ -17,13 +17,10 @@
package org.maxkey.configuration;
import org.maxkey.constants.ConstantsProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(ConstantsProperties.applicationPropertySource)
public class LoginConfig {
@Value("${maxkey.login.captcha}")
boolean captcha;

View File

@@ -17,13 +17,8 @@
package org.maxkey.constants;
import org.junit.Test;
public class ConstantsProperties {
public static final String applicationPropertySource =
"classpath:/application.properties";
public static final String kaptchaPropertySource =
"classpath:/kaptcha.properties";
@@ -38,9 +33,5 @@ public class ConstantsProperties {
return propertySource.replace(".", "-"+active+".").replaceAll("classpath:","");
}
@Test
public void classPathResourceTest() {
System.out.println(classPathResource(applicationPropertySource));
System.out.println(classPathResource(applicationPropertySource,"active"));
}
}

View File

@@ -21,13 +21,13 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.joda.time.DateTime;
import org.maxkey.cache.CacheFactory;
import org.maxkey.util.PathUtils;
import org.slf4j.Logger;
@@ -36,6 +36,8 @@ import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -172,21 +174,15 @@ public class InitializeContext extends HttpServlet {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =
((PropertySourcesPlaceholderConfigurer) applicationContext
.getBean("propertySourcesPlaceholderConfigurer"));
WebContext.properties = (Properties) propertySourcesPlaceholderConfigurer
WebContext.properties = (StandardEnvironment) propertySourcesPlaceholderConfigurer
.getAppliedPropertySources()
.get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME)
.get(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME)
.getSource();
Set<Object> keyValue = WebContext.properties.keySet();
SortedSet<String> keyValueSet = new TreeSet<String>();
// sort key
for (Iterator<Object> it = keyValue.iterator(); it.hasNext();) {
String key = (String) it.next();
keyValueSet.add(key);
}
// out
for (Iterator<String> it = keyValueSet.iterator(); it.hasNext();) {
String key = (String) it.next();
_logger.trace(key + " = " + WebContext.properties.get(key));
Iterator<PropertySource<?>> it =WebContext.properties.getPropertySources().iterator();
while(it.hasNext()) {
_logger.debug("propertySource " + it.next());
}
_logger.trace("-----------------------------------------------------------");
}
@@ -223,7 +219,9 @@ public class InitializeContext extends HttpServlet {
_logger.info("+ Version "
+ WebContext.properties.getProperty("application.formatted-version"));
_logger.info("+");
_logger.info("+ "+ ((char)0xA9) + "Copyright 2018-2021 https://www.maxkey.top/");
_logger.info("+ "+ ((char)0xA9) + "Copyright 2018-"
+ (new DateTime().getYear())
+ " https://www.maxkey.top/");
_logger.info("+ Licensed under the Apache License, Version 2.0 ");
_logger.info("-----------------------------------------------------------");
}

View File

@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -37,6 +36,7 @@ import org.maxkey.web.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.security.core.Authentication;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -55,7 +55,7 @@ public final class WebContext {
final static Logger _logger = LoggerFactory.getLogger(WebContext.class);
public static Properties properties;
public static StandardEnvironment properties;
public static ApplicationContext applicationContext;