Build API Interfaces Instantly with Dataway in Spring Boot
This tutorial walks through integrating Dataway—a UI‑driven, code‑free API configuration tool based on DataQL—into a Spring Boot project, covering Maven dependencies, property settings, datasource setup, Hasor module integration, enabling annotations, and publishing a test endpoint.
Introduction
Dataway is an interface‑configuration tool built on DataQL that lets you create functional APIs without writing any Java code. It provides a UI for configuring, testing, and publishing APIs, and runs as a JAR sharing the same HTTP port as your Spring Boot application, making it easy to adopt in existing projects.
Step 1: Add Required 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>hasor-spring bridges Spring and Hasor, while hasor-dataway provides the Dataway functionality.
Step 2: Configure Dataway in application.properties
# Enable Dataway (required)
HASOR_DATAQL_DATAWAY=true
# Enable Dataway admin UI (required)
HASOR_DATAQL_DATAWAY_ADMIN=true
# API base path (optional, default /api/)
HASOR_DATAQL_DATAWAY_API_URL=/api/
# UI base path (optional, default /interface-ui/)
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
# SQL dialect (recommended)
HASOR_DATAQL_FX_PAGE_DIALECT=mysqlOnly the two boolean flags are mandatory; the others have sensible defaults.
Step 3: Configure the Data Source
Add the following Maven dependencies for MySQL, Druid, and Spring JDBC:
<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>Then add the datasource properties:
# Database connection
spring.datasource.url=jdbc:mysql://<em>host</em>:3306/example
spring.datasource.username=<em>user</em>
spring.datasource.password=<em>password</em>
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 your project already defines a datasource, you can skip this step.
Step 4: Inject the DataSource into the Hasor Container
@DimModule
@Component
public class ExampleModule implements SpringModule {
@Autowired
private DataSource dataSource;
@Override
public void loadModule(ApiBinder apiBinder) throws Throwable {
// Transfer Spring's DataSource to Hasor
apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
}
}This module is discovered by Hasor at startup and registers the datasource.
Step 5: Enable Hasor in Spring Boot
@EnableHasor
@EnableHasorWeb
@SpringBootApplication(scanBasePackages = { "net.example.hasor" })
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}Simply add the two annotations to your main class.
Step 6: Run the Application
When the application starts you will see Hasor boot messages such as:
_ _ ___
| | | | | _ |
| |__| | __ _ ___ ___ _ __ | |_) | __ _ __ _ | |
| __ |/ _` / __|/ _ | '__| | _ < / _` / _ | __|
| | | | (_| __ (_) | | | |_) | (_) | (_) | |_
|_| |_|__,_|___/___/|_| |____/ ___/ ___/ __|The logs also confirm that Dataway is active, e.g., dataway api workAt /api/ and dataway admin workAt /interface-ui/.
Step 7: Open the Interface Management UI
Visit http://127.0.0.1:8080/interface-ui/ in a browser to see the Dataway UI.
Step 8: Create a New API
Dataway supports two script modes: raw SQL and DataQL. In SQL mode you can write a simple SELECT statement and see the result instantly.
In DataQL mode the same query is expressed as:
var query = @@sql()<%
select * from interface_info
%>
return query();The @@sql() block defines an external SQL snippet that is stored in the query variable.
Step 9: Publish and Test the API
After saving, publish the API (choose GET for simplicity). Then request http://127.0.0.1:8080/api/demos to see the returned data.
Conclusion
By following these steps you can integrate Dataway into a Spring Boot project and configure APIs without writing any Java mapping code. This dramatically reduces development effort and improves iteration speed for legacy applications.
Useful Links
Dataway official manual: https://www.hasor.net/web/dataway/about.html
Dataway project on OSChina: https://www.oschina.net/p/datawayDataQL
DataQL documentation: https://www.hasor.net/web/dataql/what_is_dataql.html
Hasor homepage: https://www.hasor.net/web/index.html
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
