Backend Development 14 min read

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

This article provides a comprehensive, step‑by‑step tutorial on how to integrate Dataway—a DataQL‑based API configuration tool—into a Spring Boot application using Hasor, covering dependency setup, configuration, datasource integration, module loading, enabling Hasor, launching the app, and creating and testing APIs through the built‑in UI.

Top Architect
Top Architect
Top Architect
Integrating Dataway with Spring Boot: A Step‑by‑Step Guide

Dataway is an interface configuration tool built on DataQL that allows developers to define and manage APIs without writing any code. By embedding Dataway as a JAR and sharing the same HTTP port with the application, it offers a one‑stop UI for configuring, testing, and publishing APIs, which can greatly improve iteration speed and reduce development costs for legacy projects.

Because Dataway belongs to the Hasor ecosystem, the first step is to integrate Hasor with Spring Boot. The official documentation recommends adding the following 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 package has missing UI resources -->
</dependency>

After adding the dependencies, configure Dataway in application.properties to enable the feature and set the API and UI paths:

# 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

Dataway requires two tables, interface_info and interface_release . Their creation scripts (MySQL syntax) are provided in the Dataway JAR under META-INF/hasor-framework/mysql and should be executed before starting the application.

Next, add a datasource to the Spring Boot project. The tutorial uses Druid together with MySQL and the Spring Boot JDBC 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):

# db
spring.datasource.url=jdbc:mysql://
:3306/example
spring.datasource.username=
spring.datasource.password=
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

To make the datasource available to Hasor, create a module that implements SpringModule and inject the datasource:

@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));
    }
}

Enable Hasor in the Spring Boot main class with two annotations:

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

When the application starts, you will see Hasor boot messages confirming that Dataway is active and that the API and UI endpoints are registered (e.g., /api/ and /interface-ui/ ).

Open a browser and navigate to http://127.0.0.1:8080/interface-ui/ to access the Dataway UI. From there you can create a new API, choose either SQL or DataQL mode, write the query, and publish it. For example, a simple SQL query on the interface_info table can be executed directly, and the result is shown instantly.

In DataQL mode, the same query is written as:

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

After saving and publishing the API (e.g., using the GET method), you can call it via http://127.0.0.1:8080/api/demos and receive the expected JSON response.

The tutorial concludes that Dataway provides a novel, code‑free way to define and manage APIs within a Spring Boot project, eliminating the need for traditional DAO/BO/VO/Controller layers and significantly simplifying backend development.

Spring BootAPI ConfigurationDataQLDatawayHasor
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn 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.