Skip to content

Latest commit

 

History

History
180 lines (126 loc) · 8.3 KB

README-English.md

File metadata and controls

180 lines (126 loc) · 8.3 KB

2.Server-side deployment

JDBC Demo:

APIJSONDemo is a simple demo for testing with APIJSON + SpringBoot + MySQL + PostgreSQL, configure database in DemoSQLConfig;
APIJSONBoot is a complex demo for production with APIJSON + SpringBoot + MySQL + PostgreSQL + SQLServer + TDengine, configure database in DemoSQLConfig;
APIJSONFinal is a complex demo for production with APIJSON + SpringBoot + MySQL + PostgreSQL, configure database in DemoSQLConfig.

Connection Pool Demo:

APIJSONDemo-Druid is a simple demo for testing with APIJSON + SpringBoot + Druid + MySQL + PostgreSQL, configure database in application.yml;
APIJSONDemo-HikariCP is a simple demo for testing with APIJSON + SpringBoot + HikariCP + MySQL + PostgreSQL, configure database in application.yml;
APIJSONBoot-MultiDataSource is a complex demo for production with APIJSON + SpringBoot + Druid + HikariCP + PostgreSQL + SQLServer + TDengine + Dameng, configure database in application.yml,
and the APIAuto source code is in src/main/resources/static, you can test APIs after open http://localhost:8080 with a browser.

Sharding Demo:

APIJSONDemo-ShardingSphere is a simple demo for testing with APIJSON + SpringBoot + ShardingSphere + MySQL + PostgreSQL, configure database in application.yml, application-sharding-databases.properties, etc.

BigData & OLAP Demo

APIJSONBoot-BigData is a complex demo for production with APIJSON + SpringBoot + Presto + Trino + Elasticsearch.


You can use either Eclipse for JavaEE or IntelllJ IDEA Ultimate to make installation.
For both, first download the project and save it to a path.


2.1 Requirements

JDK(Java Development Kit): 1.8+
Maven: 3.0+
Database: MySQL/PostgreSQL/Oracle/DB2/SQLServer/TiDB/ClickHouse/TDengine ..


2.2 Import MySQL table files

This Server project needs MySQL Server and MySQLWorkbench. Please make sure that both of them are installed.

My config is Windows 7 + MySQL Community Server 5.7.16 + MySQLWorkbench 6.3.7 and OSX EI Capitan + MySQL Community Server 5.7.16 + MySQLWorkbench 6.3.8. Systems and softwares are all 64 bit.

Start MySQLWorkbench > Enter a connection > Click Server menu > Data Import > Select the path of your .sql file > Start Import > Refresh SCHEMAS. Now you should see tables are added successfully.


2.3 Installing with Eclipse

2.3.1 prerequisites

Eclipse Java EE IDE for Web Developers 4.5.1+

2.3.2 Opening the project with Eclipse

Open Eclipse> File > Import > Maven > Existing Maven Projects > Next > Browse > Select the path of the project you saved / APIJSON-Java-Server / APIJSONBoot > check pom.xml...apijson-demo > Finish

2.3.3 Preparing the library used in demo

In the menu at the right, click libs, right click apijson-orm.jar, click add as library. Apply the same to the rest .jar files in libs.

2.3.4 Configuration

Open apijson.demo.server.DemoSQLConfig. In line 40-61, change return values of getDBUri,getDBAccount,getDBPassword,getSchema to your own database.

	static {
		DEFAULT_DATABASE = DATABASE_MYSQL;  // TODO
		DEFAULT_SCHEMA = "sys";  // TODO  defaults: MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle: 
	}
	
	@Override
	public String getDBVersion() {
		return "5.7.22";  // "8.0.11";  // TODO
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBUri() {
		// add userSSL=false for MySQL 8.0+  return "jdbc:mysql://localhost:3306?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
		// for MySQL not greater than 5.7
		return "jdbc:mysql://localhost:3306?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"; // TODO TiDB can be used as MySQL, its defaut port is 4000
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBAccount() {
		return "root";  // TODO
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBPassword() {
		return "apijson"; // TODO TiDB can be used as MySQL, its defaut password is an empty string ""
	}

Note: Instead of this step, you can also import your database.

2.3.5 Running the application

In Eclipse, in the menu on the top, click Run>Run As>Java Application>choose APIJSONApplication>OK

2.4 Installing with IntellIJ IDEA Ultimate

2.4.1 Opening the project

Open > Select the path of the project/APIJSON-Java-Server/APIJSONBoot > OK

2.4.2 Preparing the library used in demo

In libs, right-click apijson-orm.jar >Add as Library>OK. Apply this to all .jar files in libs.

2.4.3 Configuration

Open apijson.demo.server.DemoSQLConfig. In line 40-61, change return values of getDBUri,getDBAccount,getDBPassword,getSchema to your own database.

	static {
		DEFAULT_DATABASE = DATABASE_MYSQL;  // TODO
		DEFAULT_SCHEMA = "sys";  // TODO  defaults: MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle: 
	}
	
	@Override
	public String getDBVersion() {
		return "5.7.22";  // "8.0.11";  // TODO
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBUri() {
		// add userSSL=false for MySQL 8.0+  return "jdbc:mysql://localhost:3306?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
		// for MySQL not greater than 5.7
		return "jdbc:mysql://localhost:3306?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"; // TODO TiDB can be used as MySQL, its defaut port is 4000
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBAccount() {
		return "root";  // TODO
	}
	
	@JSONField(serialize = false)
	@Override
	public String getDBPassword() {
		return "apijson"; // TODO TiDB can be used as MySQL, its defaut password is an empty string ""
	}

2.4.4 Running the application

In the menu on the top: Run > Run > Edit Configurations > + > Application > Configuration
In Main class , choose APIJSONApplication;
In Use classpath of module , choose apijson-demo.
Click Run in the bottom.



Note: After running, you should see APIJSON test logs and in the last, it would show ‘APIJSON已启动’. If it shows ‘address already in use’, that means port 8080 has been used . You need tochange the port. See how to change ports for a Spring Boot Application.


2.5.Test connection

Open http://localhost:8080/get/{} with a browser
If it shows:

{
  "code": 200,
  "msg": "success"
}

Then it's a success.

If it shows '404 Not Found', please close the firewall of your machine.
Google other quetions if they appear.


2.6.Test APIs

Use APIAuto, Postman or another HTTP API test tool, the request form is HTTP POST JSON, see more on the Document
https://github.com/Tencent/APIJSON/blob/master/Document-English.md