Backend Development 15 min read

Integrating Dataway with Spring Boot: A Step‑by‑Step Tutorial

This article explains how to integrate the Dataway interface‑configuration tool into a Spring Boot project by adding Hasor dependencies, configuring Dataway properties, creating required database tables, setting up the data source, wiring Hasor modules, enabling Hasor in the application, and finally creating and testing a Dataway API without writing any business code.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Integrating Dataway with Spring Boot: A Step‑by‑Step Tutorial

Dataway is a UI‑driven interface configuration tool built on DataQL that lets developers define APIs without writing code; it runs as an embedded jar sharing the same HTTP port as the host application, making it easy to adopt in legacy projects.

Step 1: Add the required Maven dependencies

<dependency>
    <groupId>net.hasor</groupId>
    <artifactId>hasor-spring</artifactId>
    <version>4.1.3</version>
</dependency>
<dependency>
    <groupId>net.hasor</groupId>
    <artifactId>hasor-dataway</artifactId>
    <version>4.1.3-fix20200414</version>
    <!-- 4.1.3 has UI resource issues -->
</dependency>

The hasor-spring module bridges Spring and Hasor, while hasor-dataway provides the Dataway capabilities.

Step 2: Configure Dataway in application.properties

# Enable Dataway (default false)
HASOR_DATAQL_DATAWAY=true

# Enable Dataway admin UI (default false)
HASOR_DATAQL_DATAWAY_ADMIN=true

# API base path (default /api/)
HASOR_DATAQL_DATAWAY_API_URL=/api/

# UI base path (default /interface-ui/)
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/

# SQL dialect (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Only the two HASOR_DATAQL_DATAWAY and HASOR_DATAQL_DATAWAY_ADMIN flags are mandatory; the others are optional.

Step 3: Create the required database tables

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_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_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);

These tables store API definitions and their release history.

Step 4: Add a Druid + MySQL datasource

# db connection
spring.datasource.url=jdbc:mysql://
: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 pool settings
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

If the project already provides a datasource, this step can be skipped.

Step 5: Register the datasource with 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));
    }
}

The module is discovered by Hasor and injects the Spring‑managed datasource.

Step 6: Enable Hasor in the Spring Boot application

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

Adding @EnableHasor and @EnableHasorWeb activates Hasor and its web UI.

Step 7: Start the application and verify the logs

2020-04-14 13:52:59.696 [main] INFO  n.h.core.context.TemplateAppContext - loadModule class net.hasor.dataway.config.DatawayModule
2020-04-14 13:52:59.697 [main] INFO  n.hasor.dataway.config.DatawayModule - dataway api workAt /api/
2020-04-14 13:52:59.704 [main] INFO  n.hasor.dataway.config.DatawayModule - dataway admin workAt /interface-ui/

When the logs show the API and UI paths, Dataway is correctly configured.

Step 8: Open the Dataway UI

Visit http://127.0.0.1:8080/interface-ui/ in a browser to see the management console.

Step 9: Create a new API

In the UI you can choose SQL or DataQL mode. An example DataQL script:

var query = @@sql()<%
    select * from interface_info
%>
return query()

Save the API, publish it (e.g., as a GET endpoint), and then call http://127.0.0.1:8080/api/demos to see the result.

Conclusion

The tutorial demonstrates that, by integrating Dataway with Spring Boot and Hasor, developers can configure fully functional APIs without writing any business‑logic code, dramatically reducing development effort for data‑access services.

JavaSQLSpring BootAPI ConfigurationDataQLDatawayHasor
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.