How to Integrate Dataway into a Spring Boot Project – A Step‑by‑Step Guide

This article walks through the complete process of adding Dataway to a Spring Boot application, covering Maven dependencies, configuration properties, database schema creation, data source setup, Hasor module integration, enabling Hasor in Spring, and finally creating and testing API endpoints using both SQL and DataQL, all illustrated with concrete code snippets and log output.

Architect
Architect
Architect
How to Integrate Dataway into a Spring Boot Project – A Step‑by‑Step Guide

Step 1: Add Maven dependencies

Include the Hasor‑Spring bridge and the Dataway module in pom.xml:

<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> <!-- UI resources missing in 4.1.3 -->
</dependency>
hasor-spring

connects Spring and Hasor; hasor-dataway adds the Dataway API‑management layer.

Step 2: Enable Dataway and initialise its tables

Add the following flags to src/main/resources/application.properties:

# Enable Dataway (default false)
HASOR_DATAQL_DATAWAY=true

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

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

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

# Recommended SQL dialect for the built‑in executor
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Dataway requires two tables. Create them with the SQL below (the scripts are packaged under META-INF/hasor-framework/mysql in the Dataway JAR):

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 'Intercept path',
    `api_status` int(2) NOT NULL COMMENT 'Status: 0 draft, 1 published, 2 changed, 3 disabled',
    `api_comment` varchar(255) NULL COMMENT 'Comment',
    `api_type` varchar(24) NOT NULL COMMENT 'Script type: SQL, DataQL',
    `api_script` mediumtext NOT NULL COMMENT 'Query script',
    `api_schema` mediumtext NULL COMMENT 'Request/response schema',
    `api_sample` mediumtext NULL COMMENT 'Sample request/response/header data',
    `api_create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
    `api_gmt_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Modification time',
    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 'Associated API ID',
    `pub_method` varchar(12) NOT NULL COMMENT 'HttpMethod: GET, PUT, POST',
    `pub_path` varchar(512) NOT NULL COMMENT 'Intercept path',
    `pub_status` int(2) NOT NULL COMMENT 'Status: 0 active, 1 inactive (may be taken offline)',
    `pub_type` varchar(24) NOT NULL COMMENT 'Script type: SQL, DataQL',
    `pub_script` mediumtext NOT NULL COMMENT 'Query script',
    `pub_script_ori` mediumtext NOT NULL COMMENT 'Original script when type is SQL',
    `pub_schema` mediumtext NULL COMMENT 'Request/response schema',
    `pub_sample` mediumtext NULL COMMENT 'Sample request/response/header data',
    `pub_release_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Publish time (no update on offline)',
    PRIMARY KEY (`pub_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API publish history';

CREATE INDEX idx_interface_release ON interface_release (pub_api_id);

Step 3: Add a MySQL datasource

Spring Boot already provides JDBC support. Add the following Maven coordinates to bring in MySQL driver, Druid connection pool and the Spring Boot starter:

<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 (replace placeholders with real values):

# JDBC URL
spring.datasource.url=jdbc:mysql://<em>host</em>:3306/example
spring.datasource.username=<em>user</em>
spring.datasource.password=<em>password</em>
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 defines a datasource, this step can be omitted.

Step 4: Register the datasource with the Hasor container

Create a Hasor module that receives the Spring‑managed DataSource and installs the JDBC module:

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

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

Hasor invokes loadModule during startup, making the datasource available to Dataway.

Step 5: Bootstrap 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);
    }
}

The two annotations are sufficient to start Hasor alongside Spring.

Step 6: Verify startup logs

When the application launches, the console should contain entries similar to:

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  net.hasor.dataway.config.DatawayModule - dataway api workAt /api/
2020-04-14 13:52:59.704 [main] INFO  net.hasor.dataway.config.DatawayModule - dataway admin workAt /interface-ui/
... (additional controller mappings) ...

Seeing the /api/ and /interface-ui/ mappings confirms that Dataway is active.

Step 7: Use the Dataway management UI

Open a browser and navigate to http://127.0.0.1:8080/interface-ui/. The UI allows you to define, publish and test APIs without writing Java code.

Dataway UI
Dataway UI

Create a simple SQL API

In the UI, choose the SQL script mode and enter a SELECT statement against the interface_info table. After saving, the API is immediately testable.

SQL query result
SQL query result

Create a DataQL API

DataQL can embed external SQL blocks. The following script defines a variable query that runs a raw SQL statement and returns its result:

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

The @@sql()<% … %> construct creates an external SQL snippet; the surrounding DataQL returns the execution result.

Save the API (e.g., as a GET endpoint) and invoke it via http://127.0.0.1:8080/api/demos. The response is a JSON payload containing the query result.

API response
API response

Summary

This guide shows how to integrate Hasor Dataway into a Spring Boot project:

Add the required Maven artifacts.

Enable Dataway via configuration flags and create the two schema tables.

Provide a MySQL datasource (or reuse an existing one) and expose it to Hasor.

Bootstrap Hasor with @EnableHasor and @EnableHasorWeb.

Verify that the Dataway modules are loaded and the API/UI paths are registered.

Use the web UI to define APIs in either raw SQL or DataQL, publish them, and call them without additional Java code.

Useful references (plain URLs):

Dataway official documentation: https://www.hasor.net/web/dataway/about.html

Dataway project on OSChina: https://www.oschina.net/p/dataway

DataQL manual: https://www.hasor.net/web/dataql/what_is_dataql.html

Hasor homepage: https://www.hasor.net/web/index.html

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSQLSpring BootAPI ConfigurationDataQLDatawayHasor
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

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.