Step‑by‑Step Integration of Dataway into a Spring Boot Application
This guide explains how to embed Dataway—a DataQL‑based API configuration tool—into a Spring Boot project by adding Hasor dependencies, configuring Dataway properties, setting up a MySQL datasource, wiring Hasor modules, enabling Hasor annotations, and finally creating and publishing a simple API without writing any Java controller code.
Dataway is a UI‑driven tool built on DataQL that lets developers configure, test, and publish APIs without writing code. It runs as an embedded JAR sharing the same HTTP port as the host application, making it easy to adopt in legacy projects and reduce development effort.
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 lacks UI resources -->
</dependency>These two artifacts integrate Hasor with Spring and provide the Dataway UI.
Step 2 – Enable Dataway in application.properties
# Enable Dataway (required)
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI (required)
HASOR_DATAQL_DATAWAY_ADMIN=true
# Optional paths and SQL dialect
HASOR_DATAQL_DATAWAY_API_URL=/api/
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
HASOR_DATAQL_FX_PAGE_DIALECT=mysqlOnly the first two properties are mandatory; the others customize URLs and the SQL dialect.
Step 3 – Configure the MySQL 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 {
// Transfer Spring's DataSource into Hasor
apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
}
}The module is discovered by Spring and injects the datasource into 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 UI.
Step 6 – Run the application
When the application starts, Hasor prints a welcome banner and logs showing that the Dataway API and admin UI are mapped to /api/ and /interface-ui/ respectively.
Step 7 – Open the Dataway UI
Visit http://127.0.0.1:8080/interface-ui/ in a browser to see the management console.
Step 8 – Create a new API
Dataway supports both DataQL and raw SQL. For a SQL‑based API, define the query as:
var query = @sql()<%
select * from interface_info
%>;
return query();Save the API, publish it (e.g., as a GET endpoint), and then call http://127.0.0.1:8080/api/demos to receive the result.
Conclusion
The tutorial demonstrates that, with a few configuration steps, developers can expose database tables as HTTP APIs using Dataway, eliminating the need for manual mapper, service, or controller code.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
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.