How to Integrate Dataway with Spring Boot for Zero‑Code API Configuration

This tutorial walks through integrating Dataway into a Spring Boot project, covering dependency setup, Dataway configuration, database table creation, data source integration, Hasor module registration, enabling Hasor, running the application, accessing the UI, and creating APIs using SQL or DataQL, all without writing custom code.

Programmer DD
Programmer DD
Programmer DD
How to Integrate Dataway with Spring Boot for Zero‑Code API Configuration

Dataway Introduction

Dataway is an interface‑configuration tool built on DataQL service aggregation. It lets users configure, test, smoke‑test, and publish APIs through a UI without writing code, and runs as an embedded JAR sharing the same HTTP port as the application.

Step 1: Add 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 has UI resource issue -->
</dependency>

Step 2: Configure Dataway and Initialize Tables

Add the following properties to application.properties (only the two highlighted ones are mandatory):

# Enable Dataway (required)
HASOR_DATAQL_DATAWAY=true

# Enable Dataway admin UI (required)
HASOR_DATAQL_DATAWAY_ADMIN=true

# Optional settings
HASOR_DATAQL_DATAWAY_API_URL=/api/
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/
HASOR_DATAQL_FX_PAGE_DIALECT=mysql

Dataway needs two tables. Create them with the following MySQL statements (found in the Dataway JAR under META-INF/hasor-framework/mysql).

CREATE TABLE `interface_info` (
    `api_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `api_method` varchar(12) NOT NULL COMMENT 'HttpMethod: GET,PUT,POST',
    `api_path` varchar(512) NOT NULL COMMENT 'Intercept path',
    `api_status` int(2) NOT NULL COMMENT '0 draft,1 published,2 changed,3 disabled',
    `api_comment` varchar(255) NULL COMMENT 'Comment',
    `api_type` varchar(24) NOT NULL COMMENT 'Script type: SQL,DataQL',
    `api_script` mediumtext NOT NULL COMMENT 'Query script',
    `api_schema` mediumtext NULL COMMENT 'Request/response structure',
    `api_sample` mediumtext NULL COMMENT 'Sample data',
    `api_create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Create time',
    `api_gmt_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Modify time',
    PRIMARY KEY (`api_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API';

CREATE TABLE `interface_release` (
    `pub_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Publish ID',
    `pub_api_id` int(11) NOT NULL COMMENT 'Associated API ID',
    `pub_method` varchar(12) NOT NULL COMMENT 'HttpMethod: GET,PUT,POST',
    `pub_path` varchar(512) NOT NULL COMMENT 'Intercept path',
    `pub_status` int(2) NOT NULL COMMENT '0 active,1 inactive',
    `pub_type` varchar(24) NOT NULL COMMENT 'Script type: SQL,DataQL',
    `pub_script` mediumtext NOT NULL COMMENT 'Query script',
    `pub_script_ori` mediumtext NOT NULL COMMENT 'Original script for SQL',
    `pub_schema` mediumtext NULL COMMENT 'Request/response structure',
    `pub_sample` mediumtext NULL COMMENT 'Sample data',
    `pub_release_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Release time',
    PRIMARY KEY (`pub_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API release history';

CREATE INDEX idx_interface_release ON interface_release (pub_api_id);

Step 3: Configure Data Source

Use Druid + MySQL with Spring Boot:

<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=1

Step 4: Register Data Source in 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));
    }
}

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);
    }
}

Step 6: Run the Application

During startup you will see logs confirming Dataway API and admin UI paths, e.g. /api/ and /interface-ui/, indicating successful configuration.

Step 7: Access the Management UI

Open http://127.0.0.1:8080/interface-ui/ in a browser to view the Dataway interface.

Dataway UI screenshot
Dataway UI screenshot

Step 8: Create an API

Dataway supports both SQL and DataQL modes. Example SQL query: SELECT * FROM interface_info; Equivalent DataQL snippet:

var query = @sql()<% 
    select * from interface_info
%> 
return query();

Save and publish the API (e.g., using GET). After publishing, request http://127.0.0.1:8080/api/demos to see the result.

Conclusion

By following these steps you can integrate Dataway into a Spring Boot project and configure APIs without writing any business‑logic code, dramatically reducing development effort and improving iteration speed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLSpring BootAPI ConfigurationDataQLDatawayHasor
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.