应用场景:项目系统配置项
fineely-config可在中央Maven存储库中获得。Maven 用户将其添加到您的POM.
<dependency>
<groupId>com.fineely</groupId>
<artifactId>fineely-config</artifactId>
<version>1.0.6</version>
</dependency>
Gradle 用户将此添加到您的build.gradle.
implementation 'com.fineely:fineely-config:1.0.6'
如何使用:
配置文件application.yml如下:
spring data jpa可以添加 ddl-auto会自己生成表
spring:
jpa:
hibernate:
ddl-auto: update
fineely:
config:
datasource: jpa
mybatis,可以使用第三方生成表,或者直接执行sql
fineely:
config:
datasource: mybatis
配置sql如下:
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
CREATE TABLE IF
NOT EXISTS `config` (
`CONFIG_ID` INT ( 11 ) NOT NULL AUTO_INCREMENT COMMENT 'CONFIG_ID',
`CONFIG_CODE` VARCHAR ( 64 ) CHARACTER
SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Configuration encoding',
`LAST_MODIFY_TIME` datetime DEFAULT NULL COMMENT 'Modification time',
`CONFIG_VALUE` text CHARACTER
SET utf8 COLLATE utf8_general_ci COMMENT 'Configuration values',
`CONFIG_CATEGORY` VARCHAR ( 32 ) CHARACTER
SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Configuration Category',
PRIMARY KEY ( `CONFIG_ID` ) USING BTREE
) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 ROW_FORMAT = DYNAMIC COMMENT = 'Basic Configuration Table';
SET FOREIGN_KEY_CHECKS = 1;
定义自己的配置类,目前版本只支持基本数据类型
package com.example;
import com.fineelyframework.config.core.entity.ConfigSupport;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class SystemConfig implements ConfigSupport {
private String code = "example";
// Currently, only basic data types are supported
}
启动类添加注解@EnableAutoConfigScan
包路径为:配置类的路径
@EnableAutoConfigScan({"com.example"}) // configure the package path of the class
@SpringBootApplication(scanBasePackages = {"com.example"})
public class WebApplication {
public static void main(String[] args) {
SpringApplication.run(WebApplication.class, args);
}
}
获取配置类
修改配置类
参考: GitHub - Big-billed-shark/fineely-config