Backend Development 14 min read

Integrating Dataway with Spring Boot for API Configuration

This article provides a step‑by‑step guide on integrating the open‑source Dataway tool with a Spring Boot application, covering dependency inclusion, configuration of Dataway and data sources, module setup, enabling Hasor, and creating and testing API endpoints without writing custom code.

IT Xianyu
IT Xianyu
IT Xianyu
Integrating Dataway with Spring Boot for API Configuration

Dataway is an open‑source tool built on DataQL that enables developers to configure, test, smoke‑test, and publish APIs through a UI without writing any code, and it can be embedded as a JAR sharing the same HTTP port as the application.

The embedded integration model allows legacy projects to adopt Dataway non‑intrusively, improving iteration efficiency and reducing development costs.

Dataway provides a DataQL configuration capability that lets many development scenarios be completed by configuration alone, eliminating the need for Mapper, BO, VO, DO, DAO, Service, and Controller layers.

To use Dataway in a Spring Boot project, first add the required Maven dependencies:

<dependency>
    <groupId>net.hasor</groupId>
    <artifactId>hasor-spring</artifactId>
    <version>4.1.6</version>
</dependency>
<dependency>
    <groupId>net.hasor</groupId>
    <artifactId>hasor-dataway</artifactId>
    <version>4.1.6</version>
</dependency>

Configure Dataway in application.properties and enable the required flags:

# Enable Dataway
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI
HASOR_DATAQL_DATAWAY_ADMIN=true
# API base path (optional)
HASOR_DATAQL_DATAWAY_API_URL=/api/
# UI base path (optional)
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
# SQL dialect (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Dataway requires two tables; the MySQL DDL can be found in the JAR under META-INF/hasor-framework/mysql :

CREATE TABLE `interface_info` (
    `api_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `api_method` varchar(12) NOT NULL COMMENT 'HttpMethod:GET、PUT、POST',
    `api_path` varchar(512) NOT NULL COMMENT '拦截路径',
    `api_status` int(2) NOT NULL COMMENT '状态:0草稿,1发布,2有变更,3禁用',
    `api_comment` varchar(255) NULL COMMENT '注释',
    `api_type` varchar(24) NOT NULL COMMENT '脚本类型:SQL、DataQL',
    `api_script` mediumtext NOT NULL COMMENT '查询脚本:xxxxxxx',
    `api_schema` mediumtext NULL COMMENT '接口的请求/响应数据结构',
    `api_sample` mediumtext NULL COMMENT '请求/响应/请求头样本数据',
    `api_option` mediumtext NULL COMMENT '扩展配置信息',
    `api_create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `api_gmt_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`api_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dataway 中的API';

CREATE TABLE `interface_release` (
    `pub_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Publish ID',
    `pub_api_id` int(11) 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` int(2) NOT NULL COMMENT '状态:0有效,1无效(可能被下线)',
    `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 NULL COMMENT '接口的请求/响应数据结构',
    `pub_sample` mediumtext NULL COMMENT '请求/响应/请求头样本数据',
    `pub_option` mediumtext NULL COMMENT '扩展配置信息',
    `pub_release_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '发布时间(下线不更新)',
    PRIMARY KEY (`pub_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API 发布历史。';
create index idx_interface_release on interface_release (pub_api_id);

Next, add a MySQL datasource using Druid and Spring Boot starter dependencies:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.30</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.21</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.10</version>
</dependency>

Configure the datasource in application.properties :

# db
spring.datasource.url=jdbc:mysql://xxxxxxx:3306/example
spring.datasource.username=xxxxx
spring.datasource.password=xxxxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type:com.alibaba.druid.pool.DruidDataSource
# druid
spring.datasource.druid.initial-size=3
spring.datasource.druid.min-idle=3
spring.datasource.druid.max-active=10
spring.datasource.druid.max-wait=60000
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=admin
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=1

Create a Hasor module to bridge the Spring datasource into Hasor:

@DimModule
@Component
public class ExampleModule implements SpringModule {
    @Autowired
    private DataSource dataSource = null;

    @Override
    public void loadModule(ApiBinder apiBinder) throws Throwable {
        // DataSource from Spring boot into Hasor
        apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
    }
}

Enable Hasor in the Spring Boot main class with two annotations:

@EnableHasor()
@EnableHasorWeb()
@SpringBootApplication(scanBasePackages = {"net.example.hasor"})
public class ExampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }
}

When the application starts, logs will show Dataway initialization and mapping of UI endpoints such as /api/ and /interface-ui/ , confirming successful configuration.

Open a browser at http://127.0.0.1:8080/interface-ui/ to access the Dataway UI, where you can create new API definitions. Dataway supports both DataQL and raw SQL modes; for example, a SQL query can be defined as:

var query = @@sql()<%\n    select * from interface_info\n%>\nreturn query()

After saving and publishing the API (e.g., using GET), you can call it at http://127.0.0.1:8080/api/demos and receive the configured response.

In summary, the guide demonstrates how to integrate Dataway into a Spring Boot project to configure APIs without writing any Java code, significantly simplifying backend development and reducing the need for traditional mapping layers.

JavaSpring BootAPI ConfigurationDataQLDatawayHasor
IT Xianyu
Written by

IT Xianyu

We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.