Integrating Dataway with Spring Boot: A Step‑by‑Step Tutorial
This tutorial walks through adding Dataway to a Spring Boot project by importing Hasor and Dataway dependencies, configuring Maven, setting Dataway and datasource properties, creating a Hasor module to inject the Spring DataSource, enabling Hasor annotations, launching the application, and finally using the Dataway UI to define and publish SQL or DataQL‑based APIs.
Dataway is a UI‑driven interface configuration tool built on DataQL that lets developers create, test, and publish APIs without writing Java code, and it can be embedded in existing Spring Boot applications via the Hasor framework.
Step 1 – Add Maven dependencies for Hasor‑Spring and Dataway, as well as MySQL and Druid drivers:
<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>
<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>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>Step 2 – Configure Dataway properties in application.properties :
# Enable Dataway
HASOR_DATAQL_DATAWAY=true
# Enable admin UI
HASOR_DATAQL_DATAWAY_ADMIN=true
# API base path (default /api/)
HASOR_DATAQL_DATAWAY_API_URL=/api/
# Admin UI path (default /interface-ui/)
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
# SQL dialect for pagination
HASOR_DATAQL_FX_PAGE_DIALECT=mysqlStep 3 – Configure the datasource (or skip if already present):
# db
spring.datasource.url=jdbc:mysql://HOST: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
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=1Step 4 – Bridge the Spring datasource to Hasor by creating a module that implements SpringModule and injects 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));
}
}Step 5 – Enable Hasor in the Spring Boot entry class with the annotations @EnableHasor and @EnableHasorWeb :
@EnableHasor
@EnableHasorWeb
@SpringBootApplication(scanBasePackages = { "net.example.hasor" })
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}Step 6 – Run the application . The console shows Hasor boot messages such as “dataway api workAt /api/” and “dataway admin workAt /interface‑ui/”, confirming that Dataway is active.
Step 7 – Open the Dataway UI at http://127.0.0.1:8080/interface-ui/ and create a new API. You can choose SQL mode or DataQL mode. Example SQL mode query:
var query = @sql()<%
select * from interface_info
%>
return query();After saving and publishing (e.g., using GET), the API becomes reachable at http://127.0.0.1:8080/api/demos , returning the query result.
The guide demonstrates that with only configuration and a few code snippets, developers can expose database tables as RESTful endpoints without writing traditional controller, service, DAO, or entity classes.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
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.