网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
数据源配置
datasource:
url: jdbc:pivotal:greenplum://xxx.xx.xxx.xxx:2345;DatabaseName=gpdb
username: gpadmin
password: gpadmin
driver-class-name: com.pivotal.jdbc.GreenplumDriver
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 3
min-idle: 3
max-active: 10
max-wait: 60000
stat-view-servlet:
login-username: admin
login-password: admin
p6spy配置
decorator:
datasource:
p6spy:
logging: slf4j
log-file: syp.log
log-format: executionTime:%(executionTime) | sql:%(sqlSingleLine)
dataWay核心配置
启用 Dataway 功能(默认不启用)
HASOR_DATAQL_DATAWAY: true
开启 ui 管理功能(注意生产环境必须要设置为 false,否则会造成严重的生产安全事故)
HASOR_DATAQL_DATAWAY_ADMIN: true
(可选)API工作路径
HASOR_DATAQL_DATAWAY_API_URL: /api/
(可选)ui 的工作路径,只有开启 ui 管理功能后才有效
HASOR_DATAQL_DATAWAY_UI_URL: /interface-ui/
#### 2.3 数据初始化
以下是MySQL数据库的初始化SQL:
CREATE TABLE interface_info (
api_id varchar(64) NOT NULL COMMENT ‘ID’,
api_method varchar(12) NOT NULL COMMENT ‘HttpMethod:GET、PUT、POST’,
api_path varchar(512) NOT NULL COMMENT ‘拦截路径’,
api_status varchar(4) NOT NULL COMMENT ‘状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用’,
api_comment varchar(255) NOT NULL COMMENT ‘注释’,
api_type varchar(24) NOT NULL COMMENT ‘脚本类型:SQL、DataQL’,
api_script mediumtext NOT NULL COMMENT ‘查询脚本:xxxxxxx’,
api_schema mediumtext NOT NULL COMMENT ‘接口的请求/响应数据结构’,
api_sample mediumtext NOT NULL COMMENT ‘请求/响应/请求头样本数据’,
api_option mediumtext NOT NULL COMMENT ‘扩展配置信息’,
api_create_time varchar(32) NOT NULL COMMENT ‘创建时间’,
api_gmt_time varchar(32) NOT NULL COMMENT ‘修改时间’,
PRIMARY KEY (api_id),
UNIQUE KEY uk_interface_info (api_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘Dataway 中的API’;
CREATE TABLE interface_release (
pub_id varchar(64) NOT NULL COMMENT ‘Publish ID’,
pub_api_id varchar(64) NOT NULL COMMENT ‘所属API ID’,
pub_method varchar(12) NOT NULL COMMENT ‘HttpMethod:GET、PUT、POST’,
pub_path varchar(512) NOT NULL COMMENT ‘拦截路径’,
pub_status varchar(4) NOT NULL COMMENT ‘状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用’,
pub_comment varchar(255) NOT NULL COMMENT ‘注释’,
pub_type varchar(24) NOT NULL COMMENT ‘脚本类型:SQL、DataQL’,
pub_script mediumtext NOT NULL COMMENT ‘查询脚本:xxxxxxx’,
pub_script_ori mediumtext NOT NULL COMMENT ‘原始查询脚本,仅当类型为SQL时不同’,
pub_schema mediumtext NOT NULL COMMENT ‘接口的请求/响应数据结构’,
pub_sample mediumtext NOT NULL COMMENT ‘请求/响应/请求头样本数据’,
pub_option mediumtext NOT NULL COMMENT ‘扩展配置信息’,
pub_release_time varchar(32) NOT NULL COMMENT ‘发布时间(下线不更新)’,
PRIMARY KEY (pub_id),
KEY idx_interface_release_api (pub_api_id),
KEY idx_interface_release_path (pub_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=‘Dataway API 发布历史。’;
create index idx_interface_release on interface_release (pub_api_id);
【问题二】:> 1071 - Specified key was too long; max key length is 767 bytes
【解决二】:解决:调整相应字段的长度。也可以参考这篇 [博文](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb) 解决问题。
这里再提供一下GreenPlum数据库的初始化SQL:
CREATE TABLE interface_info (
api_id VARCHAR ( 64 ) NOT NULL CONSTRAINT pk_interface_info PRIMARY KEY,
api_method VARCHAR ( 12 ) NOT NULL,
api_path VARCHAR ( 512 ) NOT NULL,
api_status VARCHAR ( 4 ) NOT NULL,
api_comment VARCHAR ( 255 ) NOT NULL,
api_type VARCHAR ( 24 ) NOT NULL,
api_script TEXT NOT NULL,
api_schema TEXT NOT NULL,
api_sample TEXT NOT NULL,
api_option TEXT NOT NULL,
api_create_time VARCHAR ( 32 ) NOT NULL,
api_gmt_time VARCHAR ( 32 ) NOT NULL
) DISTRIBUTED BY ( api_id );
CREATE UNIQUE INDEX uk_interface_info ON interface_info ( api_id, api_path );
COMMENT ON TABLE interface_info IS ‘Dataway 中的API’;
COMMENT ON COLUMN interface_info.api_id IS ‘ID’;
COMMENT ON COLUMN interface_info.api_method IS ‘HttpMethod:GET、PUT、POST’;
COMMENT ON COLUMN interface_info.api_path IS ‘拦截路径’;
COMMENT ON COLUMN interface_info.api_status IS ‘状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用’;
COMMENT ON COLUMN interface_info.api_comment IS ‘注释’;
COMMENT ON COLUMN interface_info.api_type IS ‘脚本类型:SQL、DataQL’;
COMMENT ON COLUMN interface_info.api_script IS ‘查询脚本:xxxxxxx’;
COMMENT ON COLUMN interface_info.api_schema IS ‘接口的请求/响应数据结构’;
COMMENT ON COLUMN interface_info.api_sample IS ‘请求/响应/请求头样本数据’;
COMMENT ON COLUMN interface_info.api_option IS ‘扩展配置信息’;
COMMENT ON COLUMN interface_info.api_create_time IS ‘创建时间’;
COMMENT ON COLUMN interface_info.api_gmt_time IS ‘修改时间’;
CREATE TABLE interface_release (
pub_id VARCHAR ( 64 ) NOT NULL CONSTRAINT pk_interface_release PRIMARY KEY,
pub_api_id VARCHAR ( 64 ) NOT NULL,
pub_method VARCHAR ( 12 ) NOT NULL,
pub_path VARCHAR ( 512 ) NOT NULL,
pub_status VARCHAR ( 4 ) NOT NULL,
pub_comment VARCHAR ( 255 ) NOT NULL,
pub_type VARCHAR ( 24 ) NOT NULL,
pub_script TEXT NOT NULL,
pub_script_ori TEXT NOT NULL,
pub_schema TEXT NOT NULL,
pub_sample TEXT NOT NULL,
pub_option TEXT NOT NULL,
pub_release_time VARCHAR ( 32 ) NOT NULL
) DISTRIBUTED BY ( pub_id );
COMMENT ON TABLE interface_release IS ‘Dataway API 发布记录’;
COMMENT ON COLUMN interface_release.pub_id IS ‘Publish ID’;
COMMENT ON COLUMN interface_release.pub_api_id IS ‘所属API ID’;
COMMENT ON COLUMN interface_release.pub_method IS ‘HttpMethod:GET、PUT、POST’;
COMMENT ON COLUMN interface_release.pub_path IS ‘拦截路径’;
COMMENT ON COLUMN interface_release.pub_status IS ‘状态:-1-删除, 0-草稿,1-发布,2-有变更,3-禁用’;
COMMENT ON COLUMN interface_release.pub_comment IS ‘注释’;
COMMENT ON COLUMN interface_release.pub_type IS ‘脚本类型:SQL、DataQL’;
COMMENT ON COLUMN interface_release.pub_script IS ‘查询脚本:xxxxxxx’;
COMMENT ON COLUMN interface_release.pub_script_ori IS ‘原始查询脚本,仅当类型为SQL时不同’;
COMMENT ON COLUMN interface_release.pub_schema IS ‘接口的请求/响应数据结构’;
COMMENT ON COLUMN interface_release.pub_sample IS ‘请求/响应/请求头样本数据’;
COMMENT ON COLUMN interface_release.pub_option IS ‘扩展配置信息’;
COMMENT ON COLUMN interface_release.pub_release_time IS ‘发布时间(下线不更新)’;
CREATE INDEX idx_interface_release_api ON interface_release ( pub_api_id );
CREATE INDEX idx_interface_release_path ON interface_release ( pub_path );
#### 2.4 数据源初始化
Spring Boot 和 Hasor 本是两个独立的容器框架,做整合之后为了使用 Dataway 的能力需要把 Spring 中的数据源设置到 Hasor 中。首先新建一个 Hasor 的 模块,并且将其交给 Spring 管理。然后把数据源通过 Spring 注入进来。
@DimModule
@Component
public class ExampleModule implements SpringModule {
@Autowired
private DataSource dataSource = null;
@Override
public void loadModule(ApiBinder apiBinder) throws Throwable {
apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
}
}
#### 2.5 启动类添加注解
两个注解 @EnableHasor() 和 @EnableHasorWeb()
@EnableHasor()
@EnableHasorWeb()
@SpringBootApplication(scanBasePackages = { “net.example.hasor” })
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
应用在启动过程中会看到 Hasor Boot 的欢迎信息。
### 3.测试
![img](https://img-blog.csdnimg.cn/img_convert/6cc910b75f6480ddf50c38e4f50e7e43.png)
![img](https://img-blog.csdnimg.cn/img_convert/7b731dea5b7e3762aa0dadb20a3b707f.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**