|
| 1 | +## <h2 id="2">2.Server-side deployment<h2/> |
| 2 | + |
1 | 3 | ### JDBC Demo:
|
2 |
| -APIJSONDemo is a simple demo for testing with APIJSON + SpringBoot, configure database in DemoSQLConfig; <br /> |
3 |
| -APIJSONBoot is a complex demo for production with APIJSON + SpringBoot, configure database in DemoSQLConfig; <br /> |
4 |
| -APIJSONFinal is a complex demo for production with APIJSON + SpringBoot, configure database in DemoSQLConfig. <br /> |
| 4 | +[APIJSONDemo](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONDemo) is a simple demo for testing with APIJSON + SpringBoot, configure database in DemoSQLConfig; <br /> |
| 5 | +[APIJSONBoot](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONBoot) is a complex demo for production with APIJSON + SpringBoot, configure database in DemoSQLConfig; <br /> |
| 6 | +[APIJSONFinal](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONFinal) is a complex demo for production with APIJSON + SpringBoot, configure database in DemoSQLConfig. <br /> |
5 | 7 |
|
6 | 8 | ### Connection Pool Demo:
|
7 |
| -APIJSONDemo-Druid is a simple demo for testing with APIJSON + SpringBoot + Druid, configure database in application.yml; <br /> |
8 |
| -APIJSONDemo-HikariCP is a simple demo for testing with APIJSON + SpringBoot + HikariCP, configure database in application.yml; <br /> |
9 |
| -APIJSONBoot-MultiDataSource is a complex demo for production with multi data sources, configure database in application.yml, <br /> |
10 |
| -and the APIAuto source code is in src/main/resources/static, you can test APIs after open http://localhost:8080 with a browser. |
| 9 | +[APIJSONDemo-Druid](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONDemo-Druid) is a simple demo for testing with APIJSON + SpringBoot + Druid, configure database in application.yml; <br /> |
| 10 | +[APIJSONDemo-HikariCP](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONDemo-HikariCP) is a simple demo for testing with APIJSON + SpringBoot + HikariCP, configure database in application.yml; <br /> |
| 11 | +[APIJSONBoot-MultiDataSource](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONBoot-MultiDataSource) is a complex demo for production with multi data sources, configure database in application.yml, <br /> |
| 12 | +and the [APIAuto](https://github.com/TommyLemon/APIAuto) source code is in [src/main/resources/static](https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static), you can test APIs after open http://localhost:8080 with a browser. <br /> |
11 | 13 |
|
12 |
| -## <h2 id="2">2.Server-side deployment<h2/> |
13 |
| - |
14 |
| -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. |
| 14 | +<br /> |
| 15 | + |
| 16 | +**You can use either Eclipse for JavaEE or IntelllJ IDEA Ultimate to make installation. <br /> |
| 17 | +For both, first [download the project](https://github.com/APIJSON/APIJSON-Demo/archive/master.zip) and save it to a path.** <br /> |
15 | 18 |
|
16 |
| -### <h3 id="2.1">2.1 Installing with Eclipse<h3/> |
| 19 | +<br /> |
| 20 | + |
| 21 | +### <h3 id="2.1">2.1 Requirements<h3/> |
| 22 | +JDK(Java Development Kit): 1.8+ <br /> |
| 23 | +[Maven](https://maven.apache.org/download.cgi): 3.0+ <br /> |
| 24 | +Database: MySQL/PostgreSQL/Oracle/DB2/SQLServer/TiDB/ClickHouse/TDengine .. <br /> |
17 | 25 |
|
18 |
| -#### <h4 id="2.1.1">2.1.1 prerequisites<h4/> |
19 |
| - |
20 |
| -Java Development Kit(JDK): 1.8 or above |
21 |
| -[MAVEN](https://maven.apache.org/download.cgi): 3.0 or above |
22 |
| -Mysql / Oracle |
23 |
| -[Eclipse Java EE IDE](https://www.eclipse.org/downloads/)for Web Developers.Version: Mars.1 Release (4.5.1) |
| 26 | +<br /> |
| 27 | + |
| 28 | +### <h3 id="2.2">2.2 Import MySQL table files<h3/> |
| 29 | + |
| 30 | +This Server project needs [MySQL Server](https://dev.mysql.com/downloads/mysql/) and [MySQLWorkbench](https://www.mysql.com/products/workbench/). Please make sure that both of them are installed.<br /> |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +<br /> |
| 37 | + |
| 38 | +### <h3 id="2.3">2.3 Installing with Eclipse<h3/> |
24 | 39 |
|
25 |
| -#### <h4 id="2.1.2">2.1.2 Opening the project with Eclipse<h4/> |
| 40 | +#### <h4 id="2.3.1">2.3.1 prerequisites<h4/> |
| 41 | +[Eclipse Java EE IDE](https://www.eclipse.org/downloads/) for Web Developers 4.5.1+ |
| 42 | + |
| 43 | +#### <h4 id="2.3.2">2.3.2 Opening the project with Eclipse<h4/> |
26 | 44 |
|
27 | 45 | 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*
|
28 | 46 |
|
29 |
| -#### <h4 id="2.1.3">2.1.3 Preparing the library used in demo<h4/> |
| 47 | +#### <h4 id="2.3.3">2.3.3 Preparing the library used in demo<h4/> |
30 | 48 |
|
31 |
| -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. |
| 49 | +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. |
32 | 50 |
|
33 |
| -#### <h4 id="2.1.4">2.1.4 Configuration<h4/> |
| 51 | +#### <h4 id="2.3.4">2.3.4 Configuration<h4/> |
34 | 52 |
|
35 | 53 | Open apijson.demo.server.DemoSQLConfig. In line 40-61, change return values of `getDBUri`,`getDBAccount`,`getDBPassword`,`getSchema` to your own database.<br/>
|
36 | 54 |
|
@@ -68,33 +86,63 @@ Open apijson.demo.server.DemoSQLConfig. In line 40-61, change return values of `
|
68 | 86 |
|
69 | 87 | **Note**: Instead of this step, you can also [import your database](#2.2).
|
70 | 88 |
|
71 |
| -#### <h4 id="2.1.5">2.1.5 Running the application<h4/> |
| 89 | +#### <h4 id="2.3.5">2.3.5 Running the application<h4/> |
72 | 90 |
|
73 | 91 | In Eclipse, in the menu on the top, click *Run>Run As>Java Application>choose APIJSONApplication>OK*
|
74 | 92 |
|
75 |
| -### <h3 id="2.2">2.2 Import MySQL table files<h3/> |
76 |
| - |
77 |
| -This Server project needs [MySQL Server](https://dev.mysql.com/downloads/mysql/) and [MySQLWorkbench](https://www.mysql.com/products/workbench/). Please make sure that both of them are installed.<br /> |
78 |
| - |
79 |
| -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. |
80 |
| - |
81 |
| -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. |
82 |
| - |
83 |
| -### <h3 id="2.3">2.3 Installing with IntellIJ IDEA Ultimate<h3/> |
| 93 | + |
| 94 | +### <h3 id="2.4">2.4 Installing with IntellIJ IDEA Ultimate<h3/> |
84 | 95 |
|
85 |
| -#### <h4 id="2.3.1">2.3.1 Opening the project<h4/> |
| 96 | +#### <h4 id="2.4.1">2.4.1 Opening the project<h4/> |
86 | 97 |
|
87 | 98 | *Open > Select the path of the project/APIJSON-Java-Server/APIJSONBoot > OK*
|
88 | 99 |
|
89 |
| -#### <h4 id="2.3.2">2.3.2 Preparing the library used in demo<h4/> |
| 100 | +#### <h4 id="2.4.2">2.4.2 Preparing the library used in demo<h4/> |
90 | 101 |
|
91 | 102 | In libs, right-click *apijson-orm.jar >Add as Library>OK*. Apply this to all *.jar* files in libs.
|
92 | 103 |
|
93 |
| -#### <h4 id="2.3.3">2.3.3 Running the application<h4/> |
| 104 | +#### <h4 id="2.4.3">2.4.3 Configuration<h4/> |
| 105 | + |
| 106 | +Open apijson.demo.server.DemoSQLConfig. In line 40-61, change return values of `getDBUri`,`getDBAccount`,`getDBPassword`,`getSchema` to your own database.<br/> |
| 107 | + |
| 108 | +```java |
| 109 | + static { |
| 110 | + DEFAULT_DATABASE = DATABASE_MYSQL; // TODO |
| 111 | + DEFAULT_SCHEMA = "sys"; // TODO defaults: MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle: |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public String getDBVersion() { |
| 116 | + return "5.7.22"; // "8.0.11"; // TODO |
| 117 | + } |
| 118 | + |
| 119 | + @JSONField(serialize = false) |
| 120 | + @Override |
| 121 | + public String getDBUri() { |
| 122 | + // add userSSL=false for MySQL 8.0+ return "jdbc:mysql://localhost:3306?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"; |
| 123 | + // for MySQL not greater than 5.7 |
| 124 | + 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 |
| 125 | + } |
| 126 | + |
| 127 | + @JSONField(serialize = false) |
| 128 | + @Override |
| 129 | + public String getDBAccount() { |
| 130 | + return "root"; // TODO |
| 131 | + } |
| 132 | + |
| 133 | + @JSONField(serialize = false) |
| 134 | + @Override |
| 135 | + public String getDBPassword() { |
| 136 | + return "apijson"; // TODO TiDB can be used as MySQL, its defaut password is an empty string "" |
| 137 | + } |
| 138 | +``` |
| 139 | +#### <h4 id="2.4.4">2.4.4 Running the application<h4/> |
94 | 140 |
|
95 | 141 | In the menu on the top: *Run > Run > Edit Configurations > + > Application > Configuration*<br />
|
96 | 142 | In *Main class* , choose *APIJSONApplication*;<br />
|
97 | 143 | In *Use classpath of module* , choose *apijson-demo*.<br />
|
98 | 144 | Click *Run* in the bottom.
|
99 | 145 |
|
| 146 | +<br /><br /> |
| 147 | + |
100 | 148 | **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.](https://stackoverflow.com/questions/21083170/how-to-configure-port-for-a-spring-boot-application)
|
0 commit comments