feat: sa-token-quick-login 支持 SpringBoot3 项目。 Closes #IAFQNE。fix: #673

This commit is contained in:
click33
2025-03-14 19:48:45 +08:00
parent a01eef8000
commit 5b5c031bdd
13 changed files with 252 additions and 38 deletions

View File

@@ -27,6 +27,7 @@
<module>sa-token-demo-oauth2/sa-token-demo-oauth2-server</module>
<module>sa-token-demo-oauth2/sa-token-demo-oauth2-client</module>
<module>sa-token-demo-quick-login</module>
<module>sa-token-demo-quick-login-sb3</module>
<module>sa-token-demo-remember-me/sa-token-demo-remember-me-server</module>
<module>sa-token-demo-solon</module>
<module>sa-token-demo-solon-redisson</module>

View File

@@ -0,0 +1,68 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-demo-quick-login-sb3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- SpringBoot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.3</version>
</parent>
<!-- 定义 Sa-Token 版本号 -->
<properties>
<sa-token.version>1.40.0</sa-token.version>
</properties>
<dependencies>
<!-- springboot依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Sa-Token 权限认证, 在线文档https://sa-token.cc/ -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
<version>${sa-token.version}</version>
</dependency>
<!-- quick-login -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-quick-login</artifactId>
<version>${sa-token.version}</version>
</dependency>
<!-- @ConfigurationProperties -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- 热更新插件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,52 @@
package com.pj;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import cn.dev33.satoken.quick.SaQuickManager;
/**
* springboot启动之后
* @author click33
*
*/
@Component
public class SaQuicikStartup implements CommandLineRunner {
@Value("${spring.application.name:sa-quick}")
private String applicationName;
@Value("${server.port:8080}")
private String port;
@Value("${server.servlet.context-path:}")
private String path;
// @Value("${spring.profiles.active:}")
// private String active;
@Override
public void run(String... args) throws Exception {
String str = "\n------------- " + applicationName + " 启动成功 (" + getNow() + ") -------------\n" +
" - home: " + "http://localhost:" + port + path + "\n" +
" - name: " + SaQuickManager.getConfig().getName() + "\n"+
" - pwd : " + SaQuickManager.getConfig().getPwd() + "\n";
System.out.println(str);
}
/**
* 返回系统当前时间的YYYY-MM-dd hh:mm:ss 字符串格式
*/
private static String getNow(){
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
}

View File

@@ -0,0 +1,13 @@
package com.pj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SaTokenQuickSb3DemoApplication {
public static void main(String[] args) {
SpringApplication.run(SaTokenQuickSb3DemoApplication.class, args);
}
}

View File

@@ -0,0 +1,27 @@
package com.pj.test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.util.SaTokenConsts;
/**
* 测试专用Controller
* @author click33
*
*/
@RestController
public class TestController {
// 浏览器访问测试: http://localhost:8081
@RequestMapping({"/"})
public String index() {
String str = "<br />"
// + "<h1 style='text-align: center;'>Welcome to the system</h1>"
+ "<h1 style='text-align: center;'>资源页 (登录后才可进入本页面) </h1>"
+ "<hr/>"
+ "<p style='text-align: center;'> Sa-Token " + SaTokenConsts.VERSION_NO + " </p>";
return str;
}
}

View File

@@ -0,0 +1,31 @@
# 端口
server:
port: 8081
# Sa-Token-Quick-Login 配置
sa:
# 登录账号
name: sa
# 登录密码
pwd: 123456
# 是否自动随机生成账号密码 (此项为true时, name与pwd失效)
auto: false
# 是否开启全局认证(关闭后将不再强行拦截)
auth: true
# 登录页标题
title: Sa-Token 登录
# 是否显示底部版权信息
copr: true
# 指定拦截路径
# include: /**
# 指定排除路径
# exclude: /1.jpg
# 将本地磁盘的某个路径作为静态资源开放
# dir: file:E:\static
# 静态文件路径映射
spring:
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/, ${sa.dir:}