Integrating Dataway with Spring Boot: A Step‑by‑Step Guide
This guide explains how to embed Dataway—a DataQL‑based API configuration tool—into a Spring Boot application, covering dependency setup, property configuration, datasource integration, Hasor module wiring, enabling Hasor, launching the app, accessing the UI, creating and publishing APIs using SQL or DataQL, and verifying the results.
Dataway is a UI‑driven tool built on DataQL that lets developers configure, test, smoke‑test, and publish APIs without writing any Java code, by embedding a Jar that shares the same HTTP port as the application.
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>These bring in the Hasor‑Spring integration and the Dataway module.
Step 2: Configure Dataway in application.properties
# Enable Dataway
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI
HASOR_DATAQL_DATAWAY_ADMIN=true
# API base path (optional)
HASOR_DATAQL_DATAWAY_API_URL=/api/
# UI base path (optional)
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
# SQL dialect (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysqlOnly the first two properties are mandatory to activate Dataway.
Step 3: Configure the datasource
# 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 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=1If the project already defines a datasource, this step can be skipped.
Step 4: Register the datasource with Hasor
@DimModule
@Component
public class ExampleModule implements SpringModule {
@Autowired
private DataSource dataSource = null;
@Override
public void loadModule(ApiBinder apiBinder) throws Throwable {
// Inject Spring datasource into Hasor
apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
}
}The module is managed by Spring and passes the datasource to Hasor during startup.
Step 5: Enable Hasor in the Spring Boot main class
@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 components.
Step 6: Run the application
When the application starts, Hasor prints a welcome banner and logs such as:
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.697 [main] INFO n.hasor.dataway.config.DatawayModule - dataway admin workAt /interface-ui/These messages confirm that Dataway is active.
Step 7: Open the Dataway UI
Navigate to http://127.0.0.1:8080/interface-ui/ in a browser to see the management interface.
Step 8: Create a new API
Dataway supports both SQL and DataQL scripts. For example, a SQL‑mode query can be written as:
var query = @@sql()<%
select * from interface_info
%>
return query()The same logic expressed in DataQL uses the @@sql() block to embed raw SQL.
After saving and publishing the API (e.g., using GET), you can call it at http://127.0.0.1:8080/api/demos and receive the configured response.
Conclusion
By following these steps, developers can quickly expose database queries as HTTP APIs in a Spring Boot project without writing controller, service, or mapping code, dramatically reducing development effort and improving iteration speed.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.