How to Integrate Dataway with Spring Boot for Zero‑Code API Configuration

This article walks through step‑by‑step how to add Dataway—a DataQL‑based API configuration tool—to a Spring Boot application, covering Maven dependencies, property settings, datasource integration, Hasor module setup, enabling Hasor, and using the UI to create and publish SQL or DataQL endpoints without writing custom code.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
How to Integrate Dataway with Spring Boot for Zero‑Code API Configuration

Introduction

Dataway is an open‑source tool built on DataQL's service aggregation capability that provides a UI‑driven way to configure, test, smoke‑test, and publish APIs without writing any code. It runs as a JAR sharing the same HTTP port as the application, making integration non‑intrusive for legacy projects and reducing development cost.

Step 1: Add 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>

hasor-spring integrates Spring with Hasor, while hasor-dataway provides the Dataway functionality on top of Hasor.

Step 2: Configure Dataway and Initialize Tables

Add the following properties to application.properties :

# Enable Dataway
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI
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
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Dataway requires two tables ( interface_info and interface_release). Their MySQL DDL can be found in the Dataway JAR under META-INF/hasor-framework/mysql. Example DDL:

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 '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 data',
    `api_option` mediumtext NULL COMMENT 'Extended config',
    `api_create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Create time',
    `api_gmt_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Modify time',
    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 '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 '0 valid, 1 invalid',
    `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 (SQL only)',
    `pub_schema` mediumtext NULL COMMENT 'Request/response schema',
    `pub_sample` mediumtext NULL COMMENT 'Sample data',
    `pub_option` mediumtext NULL COMMENT 'Extended config',
    `pub_release_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Publish time',
    PRIMARY KEY (`pub_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API publish history';

CREATE INDEX idx_interface_release ON interface_release (pub_api_id);

Step 3: Configure the DataSource

Add the following Maven dependencies for MySQL, Druid, and Spring JDBC:

<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

If your project already provides a datasource, you can skip this step.

Step 4: Register the DataSource with Hasor

Create a Hasor module and let Spring inject the datasource:

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

    @Override
    public void loadModule(ApiBinder apiBinder) throws Throwable {
        // Install JDBC module with the Spring datasource
        apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
    }
}

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

Just add the two annotations to the main application class.

Step 6: Start the Application

When the application starts you will see Hasor’s welcome logs, for example:

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/
... (other controller mappings)

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

Step 7: Open the Management UI

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

Step 8: Create a New API

Dataway supports both DataQL and raw SQL. In SQL mode you can write a simple SELECT statement and see the result instantly.

Using DataQL you define a SQL block and return it:

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

The @@sql()<% ... %> syntax creates a reusable SQL snippet stored in query, which is then executed.

Step 9: Publish and Test the API

After saving, publish the API (e.g., as a GET endpoint). Then request http://127.0.0.1:8080/api/demos to see the response.

Conclusion

By following these steps you can integrate Dataway into a Spring Boot project and configure APIs without writing any Java code or mapping entities. The UI‑driven approach dramatically simplifies API creation and reduces development effort.

Useful links:

Dataway official manual: 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.

JavaSpring BootAPI ConfigurationDataQLDatawayHasor
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

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.