Step-by-Step Integration of Dataway with Spring Boot
This article provides a comprehensive tutorial on how to integrate Dataway—a DataQL‑based API configuration tool—into a Spring Boot project, covering dependency setup, configuration properties, datasource wiring, Hasor module creation, enabling Hasor, and using the Dataway UI to create and publish APIs without writing any Java code.
Dataway is a UI‑driven interface configuration tool built on DataQL that allows developers to define APIs without writing code. By embedding the Dataway UI as a JAR and sharing the same HTTP port as the application, existing projects can adopt Dataway with minimal intrusion, reducing development effort.
Step 1: Add required 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>
<!-- UI resources missing in 4.1.3 -->
</dependency>The hasor-spring module bridges Spring and Hasor, while hasor-dataway provides the Dataway capabilities.
Step 2: Configure Dataway in application.properties
# Enable Dataway (required)
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI (required)
HASOR_DATAQL_DATAWAY_ADMIN=true
# Optional paths
HASOR_DATAQL_DATAWAY_API_URL=/api/
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
# SQL dialect (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysqlOnly the first two properties are mandatory; the rest have defaults.
Step 3: Add a datasource (using Druid and MySQL)
<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> # 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
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 provides 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's DataSource into Hasor
apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
}
}The loadModule method is called during Hasor startup, allowing the Spring‑managed datasource to be used by Dataway.
Step 5: Enable Hasor in the Spring Boot entry 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, the console shows Hasor boot messages confirming that Dataway API and admin UI are registered at /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 interface.
Step 8: Create a new API
Dataway supports both SQL and DataQL scripts. For a simple SQL query you can write:
SELECT * FROM interface_info;Using DataQL the same query is expressed as:
var query = @sql()<%
select * from interface_info
%>;
return query();After saving and publishing (choose GET method), the API becomes accessible at http://127.0.0.1:8080/api/demos , returning the query result without any additional Java code.
Conclusion
The guide demonstrates that, by following these steps, developers can quickly configure and expose APIs in a Spring Boot project using Dataway, eliminating the need for manual mapper, DTO, service, or controller implementations.
Useful links:
Dataway official manual: https://www.hasor.net/web/dataway/about.html
Dataway project on OSC: https://www.oschina.net/p/dataway
DataQL manual: https://www.hasor.net/web/dataql/what_is_dataql.html
Hasor homepage: https://www.hasor.net/web/index.html
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.