Backend Development 13 min read

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

This tutorial explains how to integrate Dataway—a UI‑driven API configuration tool based on DataQL—into a Spring Boot application by adding the required Hasor dependencies, configuring Dataway properties and database tables, setting up the data source, enabling Hasor, and finally creating and publishing APIs using both SQL and DataQL modes.

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

Dataway Introduction

Dataway is an interface configuration tool built on DataQL's service aggregation capability, allowing users to configure APIs without writing code. All configuration, testing, smoke testing, and publishing are performed through a UI that runs as a JAR sharing the same HTTP port as the application, enabling non‑intrusive integration with legacy projects.

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

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

Step 2: Configure Dataway and Initialize Database Tables

# 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

Dataway requires two tables, interface_info and interface_release . Their MySQL DDL statements are provided in the original guide and should be executed before starting the application.

Step 3: Configure the Data Source

<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>
# db
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
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 data source, this step can be skipped.

Step 4: Register the Data Source in the Hasor Container

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

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

The Hasor container will call loadModule during startup, allowing the Spring‑managed data source to be used by Dataway.

Step 5: 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 the two annotations activates Hasor and its web integration.

Step 6: Start the Application

When the application starts, Hasor prints a welcome banner and logs showing the Dataway API path ( /api/ ) and the admin UI path ( /interface-ui/ ), confirming that Dataway is active.

Step 7: Open the Dataway UI

Visit http://127.0.0.1:8080/interface-ui/ in a browser to access the interface configuration page.

Step 8: Create a New API

Dataway supports two script modes: raw SQL and DataQL. In SQL mode you can write a simple SELECT statement and see the result immediately. In DataQL mode the same query is written as:

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

After defining the script, choose the HTTP method (e.g., GET), save and publish the API. Accessing http://127.0.0.1:8080/api/demos returns the configured result.

Conclusion

The guide demonstrates that, by following these steps, developers can quickly add Dataway to a Spring Boot project and configure APIs without writing any controller, mapper, or entity code, greatly simplifying backend development.

Backend DevelopmentSpring 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.