1
0
mirror of https://gitee.com/dromara/sa-token.git synced 2025-04-05 17:37:53 +08:00

完全移除 SaHistoryVersionInject 兼容类

This commit is contained in:
click33 2022-02-09 23:31:17 +08:00
parent 369d3ffb5b
commit 163053d6fa
5 changed files with 0 additions and 128 deletions
sa-token-doc/doc/use
sa-token-starter
sa-token-reactor-spring-boot-starter/src/main
java/cn/dev33/satoken/reactor/spring
resources/META-INF
sa-token-spring-boot-starter/src/main
java/cn/dev33/satoken/spring
resources/META-INF

View File

@ -29,8 +29,6 @@ sa-token:
如果你习惯于 `application.properties` 类型的配置文件,那也很好办: 百度: [springboot properties与yml 配置文件的区别](https://www.baidu.com/s?ie=UTF-8&wd=springboot%20properties%E4%B8%8Eyml%20%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E5%8C%BA%E5%88%AB)
!> 注:旧版本配置前缀为`[spring.sa-token.]`自v1.21.0开始,均改为`[sa-token.]`,目前版本暂时向下兼容,请尽快更新
### 方式2、通过代码配置
模式1

View File

@ -1,62 +0,0 @@
package cn.dev33.satoken.reactor.spring;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import cn.dev33.satoken.util.SaTokenConsts;
/**
* 兼容旧版本的配置信息注入
* <p> 目前已处理
* <p> 1. yml配置前缀 [spring.sa-token.] 更改为 [sa-token.]
* @author kong
*/
//SpringBoot 1.5.x 版本下不存在 OriginTrackedMapPropertySource 不加这个注解会导致项目无法启动
@ConditionalOnClass(OriginTrackedMapPropertySource.class)
public class SaHistoryVersionInject implements EnvironmentAware{
@Override
@SuppressWarnings("unchecked")
public void setEnvironment(Environment env) {
try {
ConfigurableEnvironment c = (ConfigurableEnvironment) env;
MutablePropertySources sources = c.getPropertySources();
// 将yml中所有 [spring.sa-token.] 开头的配置转移到 [sa-token.]
Map<String, Object> newMap = new LinkedHashMap<String, Object>();
for (PropertySource<?> source : sources) {
// 根据Name开头单词判断是否为 SpringBoot .yml 或者.properties 的配置
if(source.getName().startsWith("applicationConfig")) {
Map<String, Object> bootProp = (Map<String, Object>)source.getSource();
for (String key : bootProp.keySet()) {
if(key != null && key.startsWith("spring.sa-token.")) {
String newKey = key.substring(7);
newMap.put(newKey, bootProp.get(key));
}
}
}
}
// 追加到总配置里面
if(newMap.size() > 0) {
System.err.println("\n"
+ "Sa-Token Warning: 当前配置文件方式已过时,请更改配置前缀:原 [spring.sa-token.] 更改为 [sa-token.]\n"
+ "Sa-Token Warning: 当前版本(" + SaTokenConsts.VERSION_NO + ")暂时向下兼容,未来版本可能会完全移除旧形式");
OriginTrackedMapPropertySource source = new OriginTrackedMapPropertySource("SaHistoryVersionInjectProperty", newMap);
// 追加到末尾优先级最低
c.getPropertySources().addLast(source);
}
} catch (Exception e) {
// not handle
}
}
}

View File

@ -1,6 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.dev33.satoken.reactor.spring.SaBeanRegister,\
cn.dev33.satoken.reactor.spring.SaBeanInject,\
cn.dev33.satoken.reactor.spring.SaHistoryVersionInject,\
cn.dev33.satoken.reactor.spring.oauth2.SaOAuth2BeanRegister,\
cn.dev33.satoken.reactor.spring.oauth2.SaOAuth2BeanInject

View File

@ -1,62 +0,0 @@
package cn.dev33.satoken.spring;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import cn.dev33.satoken.util.SaTokenConsts;
/**
* 兼容旧版本的配置信息注入
* <p> 目前已处理
* <p> 1. yml配置前缀 [spring.sa-token.] 更改为 [sa-token.]
* @author kong
*/
//SpringBoot 1.5.x 版本下不存在 OriginTrackedMapPropertySource 不加这个注解会导致项目无法启动
@ConditionalOnClass(OriginTrackedMapPropertySource.class)
public class SaHistoryVersionInject implements EnvironmentAware{
@Override
@SuppressWarnings("unchecked")
public void setEnvironment(Environment env) {
try {
ConfigurableEnvironment c = (ConfigurableEnvironment) env;
MutablePropertySources sources = c.getPropertySources();
// 将yml中所有 [spring.sa-token.] 开头的配置转移到 [sa-token.]
Map<String, Object> newMap = new LinkedHashMap<String, Object>();
for (PropertySource<?> source : sources) {
// 根据Name开头单词判断是否为 SpringBoot .yml 或者.properties 的配置
if(source.getName().startsWith("applicationConfig")) {
Map<String, Object> bootProp = (Map<String, Object>)source.getSource();
for (String key : bootProp.keySet()) {
if(key != null && key.startsWith("spring.sa-token.")) {
String newKey = key.substring(7);
newMap.put(newKey, bootProp.get(key));
}
}
}
}
// 追加到总配置里面
if(newMap.size() > 0) {
System.err.println("\n"
+ "Sa-Token Warning: 当前配置文件方式已过时,请更改配置前缀:原 [spring.sa-token.] 更改为 [sa-token.]\n"
+ "Sa-Token Warning: 当前版本(" + SaTokenConsts.VERSION_NO + ")暂时向下兼容,未来版本可能会完全移除旧形式");
OriginTrackedMapPropertySource source = new OriginTrackedMapPropertySource("SaHistoryVersionInjectProperty", newMap);
// 追加到末尾优先级最低
c.getPropertySources().addLast(source);
}
} catch (Exception e) {
// not handle
}
}
}

View File

@ -1,6 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.dev33.satoken.spring.SaBeanRegister,\
cn.dev33.satoken.spring.SaBeanInject,\
cn.dev33.satoken.spring.SaHistoryVersionInject,\
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanRegister,\
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject