本指南将帮助您在5分钟内快速集成Medical License组件到您的Spring Boot医疗软件系统中。
在您的 pom.xml 中添加依赖:
<dependency>
<groupId>com.bskj.license</groupId>
<artifactId>byjc-spring-boot-starter-license</artifactId>
<version>1.0.0</version>
</dependency>
# 下载并运行密钥生成工具
java -cp byjc-spring-boot-starter-license-1.0.0.jar com.bskj.framework.license.generator.KeyGenerator private.key public.key
这将生成两个文件:
private.key - 私钥(用于签名license,请安全保存)public.key - 公钥(用于验证license,可随应用分发)# 生成license文件
java -cp byjc-spring-boot-starter-license-1.0.0.jar com.bskj.framework.license.generator.LicenseGenerator private.key license.json "您的医院名称"
在 application.yml 中添加配置:
bskj:
license:
enabled: true
file-path: "license.json"
public-key-path: "public.key"
default-strategy: "notification_only" # 推荐从宽松策略开始
@RestController
public class PatientController {
@LicenseRequired(modules = {"patient_management"})
@GetMapping("/patients")
public List<Patient> getPatients() {
return patientService.getAllPatients();
}
}
java -jar your-bskj-app.jar
🎉 恭喜! 您的应用现在已经集成了License授权功能!
bskj:
license:
enabled: true # 启用license检查
file-path: "license.json" # license文件路径
public-key-path: "public.key" # 公钥文件路径
default-strategy: "notification_only" # 授权策略
check-interval-seconds: 3600 # 检查间隔(1小时)
default-warning-days: 30 # 预警天数
bskj:
license:
notification:
log-enabled: true # 启用日志通知
email-enabled: false # 禁用邮件通知(可选)
jmx-enabled: false # 禁用JMX通知(可选)
@LicenseRequired(
modules = {"billing", "reporting"}, // 需要的模块权限
checkUserLimit = true, // 检查用户数限制
allowExpired = false, // 是否允许过期时执行
strict = false, // 严格模式
message = "需要计费和报表模块授权" // 自定义错误消息
)
// 基础权限检查
@LicenseRequired(modules = {"patient_management"})
// 检查用户数限制
@LicenseRequired(checkUserLimit = true)
// 严格模式(任何license问题都阻止执行)
@LicenseRequired(strict = true)
// 允许过期时执行(紧急功能)
@LicenseRequired(modules = {"emergency"}, allowExpired = true)
@Service
public class BusinessService {
@Autowired
private LicenseService licenseService;
public void performOperation() {
// 检查license状态
if (!licenseService.isLicenseValid()) {
throw new BusinessException("License无效");
}
// 检查模块权限
if (!licenseService.isModulePermitted("advanced_features")) {
throw new BusinessException("高级功能未授权");
}
// 检查用户数限制
if (!licenseService.isUserCountWithinLimit(getCurrentUserCount())) {
throw new BusinessException("用户数超过限制");
}
// 执行业务逻辑
doBusinessLogic();
}
}
@RestController
public class LicenseController {
@Autowired
private LicenseService licenseService;
@GetMapping("/api/license/status")
public Map<String, Object> getLicenseStatus() {
return Map.of(
"valid", licenseService.isLicenseValid(),
"status", licenseService.getLicenseStatus(),
"remainingDays", licenseService.getRemainingDays(),
"warning", licenseService.getLicenseWarningMessage()
);
}
}
@Component
public class LicenseEventListener {
@EventListener
public void handleStatusChange(LicenseStatusChangeEvent event) {
logger.info("License状态变化: {} -> {}",
event.getPreviousStatus(), event.getCurrentStatus());
}
}
Q: 应用启动时提示"License文件不存在"
# 检查配置文件中的路径是否正确
bskj:
license:
file-path: "license.json" # 确保文件存在
Q: 提示"签名验证失败"
# 确保使用正确的公钥文件
# 检查license文件是否被篡改
Q: 注解不生效
// 确保启用了AOP
@EnableAspectJAutoProxy
@SpringBootApplication
public class Application {
// ...
}
logging:
level:
com.bskj.license: DEBUG # 启用详细日志
查看完整文档:
如有问题,请查看:
🎉 恭喜您完成了快速集成! 现在您的医疗软件系统已经具备了专业的License授权功能。