| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
fate-framework 是一个基于 Java 和 Maven 构建的云服务基础框架,旨在为分布式系统开发提供统一的基础能力和扩展组件。该框架包含自动配置、核心功能、工具类、认证、数据源、日志、Redis、权限安全、Swagger 等多个模块,方便开发者按需集成。
fate-framework/ ├── fate-base-auto/ # 自动配置模块 ├── fate-base-cloud/ # 云基础模块 ├── fate-base-core/ # 核心功能模块 ├── fate-base-launch/ # 启动模块 ├── fate-base-test/ # 测试模块 ├── fate-base-utils/ # 工具类模块 ├── fate-starter-auth/ # 认证组件 ├── fate-starter-datasource/# 数据源组件 ├── fate-starter-log/ # 日志组件 ├── fate-starter-redis/ # Redis 组件 ├── fate-starter-security/ # 权限安全组件 ├── fate-starter-swagger/ # Swagger 文档组件 ├── fate-zpom/ # 统一依赖管理 └── pom.xml # 父级 Maven 配置
在项目根目录下执行:
mvn clean installSpringBoot业务模块引入fate-base-auto模块与fate-base-launch模块
<dependency>
<groupId>com.fatebug.cloud</groupId>
<artifactId>fate-base-launch</artifactId>
</dependency>
<dependency>
<groupId>com.fatebug.cloud</groupId>
<artifactId>fate-base-auto</artifactId>
<scope>provided</scope>
</dependency>
修改启动类代码为:
import com.fatebug.base.core.anno.EnableCustomConfig;
import com.fatebug.common.constants.ServiceNameConstants;
import com.fatebug.base.launch.FateApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@EnableCustomConfig//基础开关配置注解,默认包路径为com.fatebug
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class FateGateway {
public static void main(String[] args) {
// SpringApplication.run(FateGateway.class, args);
FateApplication.run(
"gateway",//模块名
FateGateway.class, args);
}
}
建立com.fatebug.base.launch.service.LauncherService类的实现类,用于设置启动参数
必须添加注解@AutoService(LauncherService.class)用于自动配置扫描
示例:
import com.fatebug.base.auto.service.AutoService;
import com.fatebug.common.constants.NacosConstant;
import com.fatebug.base.launch.service.LauncherService;
import com.fatebug.base.utils.Fate;
import com.fatebug.common.constants.ConfigConstants;
import org.springframework.boot.builder.SpringApplicationBuilder;
import java.util.Properties;
/**
* 启动参数拓展
*/
@AutoService(LauncherService.class)
public class BaseLauncherServiceImpl implements LauncherService {
/**
* 启动器
*
* @param builder 构建器
* @param appName 应用程序名称
* @param profile 配置文件
* @param isLocalDev 是本地开发
*/
@Override
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
Properties props = System.getProperties();
// 通用注册
Fate.setProperty(props, "spring.cloud.nacos.discovery.server-addr", NacosConstant.nacosAddr(profile));
Fate.setProperty(props, "spring.cloud.nacos.username", NacosConstant.NACOS_USERNAME);
Fate.setProperty(props, "spring.cloud.nacos.password", NacosConstant.NACOS_PASSWORD);
Fate.setProperty(props, "spring.cloud.nacos.config.server-addr", NacosConstant.nacosAddr(profile));
Fate.setProperty(props,"spring.cloud.nacos.config.file-extension", NacosConstant.NACOS_CONFIG_FORMAT);
Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[0].data-id", NacosConstant.sharedDataId());
// Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[0].group", NacosConstant.NACOS_CONFIG_GROUP);
Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[0].refresh", NacosConstant.NACOS_CONFIG_REFRESH);
Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[1].data-id", NacosConstant.sharedDataId(profile));
// Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[1].group", NacosConstant.NACOS_CONFIG_GROUP);
Fate.setProperty(props, "spring.cloud.nacos.config.shared-configs[1].refresh", NacosConstant.NACOS_CONFIG_REFRESH);
Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[2].data-id", NacosConstant.shareConfig(profile));
// Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[2].group", NacosConstant.NACOS_CONFIG_GROUP);
Fate.setProperty(props,"spring.cloud.nacos.config.shared-configs[2].refresh", NacosConstant.NACOS_CONFIG_REFRESH);
Fate.setProperty(props,"spring.cloud.nacos.config.namespace", NacosConstant.NAME_SPACE);
Fate.setProperty(props,"spring.cloud.nacos.discovery.namespace", NacosConstant.NAME_SPACE);
// Fate.setProperty(props,"spring.cloud.nacos.discovery.namespace", NacosConstant.NAME_SPACE_ANIXUIL);
// Fate.setProperty(props, "spring.cloud.sentinel.transport.dashboard", ConfigConstants.sentinelAddr(profile));
// Fate.setProperty(props, "spring.zipkin.base-url", ConfigConstants.zipkinAddr(profile));
// Fate.setProperty(props, "spring.datasource.dynamic.enabled", "false");
// 开启elk日志
// Fate.setProperty(props, "fate.log.elk.destination", ConfigConstants.elkAddr(profile));
// seata注册地址
// Fate.setProperty(props, "seata.service.grouplist.default", ConfigConstants.seataAddr(profile));
// seata注册group格式
// Fate.setProperty(props, "seata.tx-service-group", ConfigConstants.seataServiceGroup(appName));
// seata配置服务group
// Fate.setProperty(props, "seata.service.vgroup-mapping.".concat(ConfigConstants.seataServiceGroup(appName)), ConfigConstants.DEFAULT_MODE);
// seata注册模式配置
// Fate.setProperty(props, "seata.registry.type", ConfigConstants.NACOS_MODE);
// Fate.setProperty(props, "seata.registry.nacos.server-addr", ConfigConstants.nacosAddr(profile));
// Fate.setProperty(props, "seata.config.type", ConfigConstants.NACOS_MODE);
// Fate.setProperty(props, "seata.config.nacos.server-addr", ConfigConstants.nacosAddr(profile));
}
}Redis、数据库等配置也可以通过类似的方式进行注入
本项目采用 Apache License 2.0 开源协议。
Copyright [2025] [fatebugs]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
| Back | FazBrowse Home | New Git URL |