Backend Development 15 min read

Step‑by‑Step Integration of Dataway with Spring Boot Using Hasor

This article provides a comprehensive tutorial on integrating Dataway—a zero‑code API configuration tool based on DataQL—into a Spring Boot project via the Hasor framework, covering dependency setup, Dataway configuration, datasource binding, enabling Hasor, launching the application, and creating and testing API endpoints.

Top Architect
Top Architect
Top Architect
Step‑by‑Step Integration of Dataway with Spring Boot Using Hasor

Dataway is an interface‑configuration tool built on DataQL that allows developers to expose data access APIs without writing any Java code. It embeds a UI as a JAR, shares the same HTTP port as the host application, and works well with legacy projects because it requires no invasive changes.

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 package misses UI resources -->
</dependency>

The first dependency integrates Hasor with Spring, and the second brings Dataway functionality.

Step 2 – Configure Dataway and initialize tables

Add the following properties to application.properties (or application.yml ) to enable Dataway and its admin UI:

# 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 (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Dataway requires two MySQL tables ( interface_info and interface_release ) which are provided in the JAR under META-INF/hasor-framework/mysql . The article includes the full CREATE statements.

Step 3 – Configure the datasource

Include the usual Spring Boot JDBC and Druid dependencies and add the datasource properties:

# db
spring.datasource.url=jdbc:mysql://HOST:3306/example
spring.datasource.username=YOUR_USER
spring.datasource.password=YOUR_PASS
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 has a datasource, this step can be skipped.

Step 4 – Bind the datasource to the Hasor container

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

This module makes the Spring‑managed datasource available to Hasor.

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

Two annotations are enough to activate Hasor and its web integration.

Step 6 – Start the application

When the application boots, Hasor prints a banner and logs 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 INFO  net.hasor.dataway.config.DatawayModule - dataway api workAt /api/
2020-04-14 13:52:59.704 INFO  net.hasor.dataway.config.DatawayModule - dataway admin workAt /interface-ui/

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

Step 7 – Open the Dataway UI

Navigate to http://127.0.0.1:8080/interface-ui/ in a browser. The UI allows you to manage APIs, test queries, and publish endpoints.

Step 8 – Create a new API

Dataway supports both raw SQL and DataQL scripts. For a simple SELECT you can write:

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

After saving and publishing (choose GET method), the endpoint becomes available at http://127.0.0.1:8080/api/demos , returning the query result without any additional Java code.

Conclusion

The guide demonstrates that, by using Dataway together with Hasor and Spring Boot, developers can expose database queries as HTTP APIs in a few minutes, eliminating the need for boilerplate layers such as Mapper, Service, Controller, and DTOs.

JavaBackend DevelopmentSpring BootAPI ConfigurationDatawayHasor
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.