mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 13:34:18 +08:00
starter包架构调整
This commit is contained in:
parent
12d76e34bb
commit
82f7d7f78c
@ -17,7 +17,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import cn.dev33.satoken.SaManager;
|
import cn.dev33.satoken.SaManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sa-token整合webflux 示例
|
* Sa-Token整合webflux 示例
|
||||||
* @author kong
|
* @author kong
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +14,7 @@ import cn.dev33.satoken.reactor.filter.SaReactorFilter;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SaTokenConfigure {
|
public class SaTokenConfigure {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册 [sa-token全局过滤器]
|
* 注册 [sa-token全局过滤器]
|
||||||
*/
|
*/
|
||||||
|
@ -33,6 +33,7 @@ sa-token:
|
|||||||
|
|
||||||
|
|
||||||
### 方式2、通过代码配置
|
### 方式2、通过代码配置
|
||||||
|
方式1:
|
||||||
``` java
|
``` java
|
||||||
/**
|
/**
|
||||||
* Sa-Token代码方式进行配置
|
* Sa-Token代码方式进行配置
|
||||||
@ -58,6 +59,18 @@ public class SaTokenConfigure {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
方式2:
|
||||||
|
``` java
|
||||||
|
// 以代码的方式配置Sa-Token-Config
|
||||||
|
@Autowired
|
||||||
|
public void configSaToken(SaTokenConfig config) {
|
||||||
|
// config.setTokenName("satoken333"); // token名称 (同时也是cookie名称)
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
PS:两者的区别在于:**`方式1会覆盖yml中的配置,方式2会与yml中的配置合并`**
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
### 所有可配置项
|
### 所有可配置项
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package cn.dev33.satoken.spring;
|
package cn.dev33.satoken.reactor.spring;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.PathMatcher;
|
import org.springframework.util.PathMatcher;
|
||||||
@ -24,26 +22,15 @@ import cn.dev33.satoken.temp.SaTempInterface;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Import(SaHistoryVersionInject.class)
|
@Import({SaHistoryVersionInject.class, SaBeanRegister.class})
|
||||||
public class SaTokenSpringAutowired {
|
public class SaBeanInject {
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取配置Bean
|
|
||||||
*
|
|
||||||
* @return 配置对象
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties(prefix = "sa-token")
|
|
||||||
public SaTokenConfig getSaTokenConfig() {
|
|
||||||
return new SaTokenConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入配置Bean
|
* 注入配置Bean
|
||||||
*
|
*
|
||||||
* @param saTokenConfig 配置对象
|
* @param saTokenConfig 配置对象
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
public void setConfig(SaTokenConfig saTokenConfig) {
|
public void setConfig(SaTokenConfig saTokenConfig) {
|
||||||
SaManager.setConfig(saTokenConfig);
|
SaManager.setConfig(saTokenConfig);
|
||||||
}
|
}
|
||||||
@ -78,22 +65,12 @@ public class SaTokenSpringAutowired {
|
|||||||
SaManager.setSaTokenAction(saTokenAction);
|
SaManager.setSaTokenAction(saTokenAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取容器交互Bean (Spring版)
|
|
||||||
*
|
|
||||||
* @return 容器交互Bean (Spring版)
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public SaTokenContext getSaTokenContext() {
|
|
||||||
return new SaTokenContextForSpring();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入容器交互Bean
|
* 注入容器交互Bean
|
||||||
*
|
*
|
||||||
* @param saTokenContext SaTokenContext对象
|
* @param saTokenContext SaTokenContext对象
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
public void setSaTokenContext(SaTokenContext saTokenContext) {
|
public void setSaTokenContext(SaTokenContext saTokenContext) {
|
||||||
SaManager.setSaTokenContext(saTokenContext);
|
SaManager.setSaTokenContext(saTokenContext);
|
||||||
}
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package cn.dev33.satoken.reactor.spring;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.config.SaTokenConfig;
|
||||||
|
import cn.dev33.satoken.context.SaTokenContext;
|
||||||
|
import cn.dev33.satoken.context.SaTokenContextForThreadLocal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册Sa-Token所需要的Bean
|
||||||
|
* <p> Bean 的注册与注入应该分开在两个文件中,否则在某些场景下会造成循环依赖
|
||||||
|
* @author kong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SaBeanRegister {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置Bean
|
||||||
|
*
|
||||||
|
* @return 配置对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix = "sa-token")
|
||||||
|
public SaTokenConfig getSaTokenConfig() {
|
||||||
|
return new SaTokenConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取容器交互Bean (ThreadLocal版)
|
||||||
|
*
|
||||||
|
* @return 容器交互Bean (ThreadLocal版)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SaTokenContext getSaTokenContext() {
|
||||||
|
return new SaTokenContextForThreadLocal() {
|
||||||
|
/**
|
||||||
|
* 重写路由匹配方法
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean matchPath(String pattern, String path) {
|
||||||
|
return SaPathMatcherHolder.getPathMatcher().match(pattern, path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.reactor.spring.SaTokenSpringAutowired
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.reactor.spring.SaBeanInject
|
@ -1,9 +1,7 @@
|
|||||||
package cn.dev33.satoken.reactor.spring;
|
package cn.dev33.satoken.spring;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.PathMatcher;
|
import org.springframework.util.PathMatcher;
|
||||||
@ -12,39 +10,27 @@ import cn.dev33.satoken.SaManager;
|
|||||||
import cn.dev33.satoken.action.SaTokenAction;
|
import cn.dev33.satoken.action.SaTokenAction;
|
||||||
import cn.dev33.satoken.config.SaTokenConfig;
|
import cn.dev33.satoken.config.SaTokenConfig;
|
||||||
import cn.dev33.satoken.context.SaTokenContext;
|
import cn.dev33.satoken.context.SaTokenContext;
|
||||||
import cn.dev33.satoken.context.SaTokenContextForThreadLocal;
|
|
||||||
import cn.dev33.satoken.dao.SaTokenDao;
|
import cn.dev33.satoken.dao.SaTokenDao;
|
||||||
import cn.dev33.satoken.listener.SaTokenListener;
|
import cn.dev33.satoken.listener.SaTokenListener;
|
||||||
import cn.dev33.satoken.stp.StpInterface;
|
import cn.dev33.satoken.stp.StpInterface;
|
||||||
import cn.dev33.satoken.temp.SaTempInterface;
|
import cn.dev33.satoken.temp.SaTempInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 利用spring的自动装配来加载开发者重写的Bean
|
* 注入Sa-Token所需要的Bean
|
||||||
*
|
*
|
||||||
* @author kong
|
* @author kong
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Import(SaHistoryVersionInject.class)
|
@Import({SaBeanRegister.class, SaHistoryVersionInject.class})
|
||||||
public class SaTokenSpringAutowired {
|
public class SaBeanInject {
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取配置Bean
|
|
||||||
*
|
|
||||||
* @return 配置对象
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties(prefix = "sa-token")
|
|
||||||
public SaTokenConfig getSaTokenConfig() {
|
|
||||||
return new SaTokenConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入配置Bean
|
* 注入配置Bean
|
||||||
*
|
*
|
||||||
* @param saTokenConfig 配置对象
|
* @param saTokenConfig 配置对象
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
public void setConfig(SaTokenConfig saTokenConfig) {
|
public void setConfig(SaTokenConfig saTokenConfig) {
|
||||||
SaManager.setConfig(saTokenConfig);
|
SaManager.setConfig(saTokenConfig);
|
||||||
}
|
}
|
||||||
@ -79,30 +65,12 @@ public class SaTokenSpringAutowired {
|
|||||||
SaManager.setSaTokenAction(saTokenAction);
|
SaManager.setSaTokenAction(saTokenAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取容器交互Bean (ThreadLocal版)
|
|
||||||
*
|
|
||||||
* @return 容器交互Bean (ThreadLocal版)
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public SaTokenContext getSaTokenContext() {
|
|
||||||
return new SaTokenContextForThreadLocal() {
|
|
||||||
/**
|
|
||||||
* 重写路由匹配方法
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean matchPath(String pattern, String path) {
|
|
||||||
return SaPathMatcherHolder.getPathMatcher().match(pattern, path);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入容器交互Bean
|
* 注入容器交互Bean
|
||||||
*
|
*
|
||||||
* @param saTokenContext SaTokenContext对象
|
* @param saTokenContext SaTokenContext对象
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired(required = false)
|
||||||
public void setSaTokenContext(SaTokenContext saTokenContext) {
|
public void setSaTokenContext(SaTokenContext saTokenContext) {
|
||||||
SaManager.setSaTokenContext(saTokenContext);
|
SaManager.setSaTokenContext(saTokenContext);
|
||||||
}
|
}
|
||||||
@ -138,5 +106,4 @@ public class SaTokenSpringAutowired {
|
|||||||
SaPathMatcherHolder.setPathMatcher(pathMatcher);
|
SaPathMatcherHolder.setPathMatcher(pathMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package cn.dev33.satoken.spring;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.config.SaTokenConfig;
|
||||||
|
import cn.dev33.satoken.context.SaTokenContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册Sa-Token所需要的Bean
|
||||||
|
* <p> Bean 的注册与注入应该分开在两个文件中,否则在某些场景下会造成循环依赖
|
||||||
|
* @author kong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SaBeanRegister {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置Bean
|
||||||
|
*
|
||||||
|
* @return 配置对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix = "sa-token")
|
||||||
|
public SaTokenConfig getSaTokenConfig() {
|
||||||
|
return new SaTokenConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取容器交互Bean (Spring版)
|
||||||
|
*
|
||||||
|
* @return 容器交互Bean (Spring版)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SaTokenContext getSaTokenContext() {
|
||||||
|
return new SaTokenContextForSpring();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.spring.SaTokenSpringAutowired
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.spring.SaBeanInject
|
Loading…
Reference in New Issue
Block a user