Backend Development 14 min read

Integrating Dataway with Spring Boot for Zero‑Code API Configuration

This tutorial walks through adding Dataway to a Spring Boot project, covering Maven dependencies, configuration properties, required database tables, data‑source setup, Hasor module integration, enabling Hasor, launching the application, and creating and testing APIs using both SQL and DataQL without writing any service code.

Architecture Digest
Architecture Digest
Architecture Digest
Integrating Dataway with Spring Boot for Zero‑Code API Configuration

Dataway is an interface‑configuration tool built on Hasor DataQL that lets developers expose APIs without writing any Java code. By embedding Dataway’s UI jar into a Spring Boot application, the same HTTP port can serve both the application and the Dataway admin console.

Step 1 – Add 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 包存在UI资源缺失问题 -->
</dependency>

Step 2 – Enable Dataway and Configure Properties

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

Step 3 – Create 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 AUTO_INCREMENT=0 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 AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API 发布历史。';
create index idx_interface_release on interface_release (pub_api_id);

Step 4 – Configure Spring Boot DataSource

# 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

Step 5 – Bridge 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));
    }
}

Step 6 – Enable Hasor in Spring Boot

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

After starting the application, the console logs show messages such as dataway api workAt /api/ and dataway admin workAt /interface-ui/ , confirming that Dataway is active.

Step 7 – Access the Dataway UI

Open a browser at http://127.0.0.1:8080/interface-ui/ to reach the management console where you can create new API definitions.

Step 8 – Create an API

Dataway supports both raw SQL and DataQL. For a SQL‑based API you can write a simple SELECT * FROM interface_info query and see the result instantly. For DataQL, define a block like:

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

Save and publish the API (e.g., using the GET method). After publishing, a request to http://127.0.0.1:8080/api/demos returns the configured data.

Conclusion

The guide demonstrates how Dataway can turn a Spring Boot project into a zero‑code API gateway, eliminating the need for manual Mapper/BO/VO/DAO/Service/Controller layers and dramatically speeding up backend development.

backendSQLSpring BootAPI ConfigurationDataQLDatawayHasor
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.