Skip to content

Commit d8583de

Browse files
committed
Server: Demo 支持自定义端口号;DemoSQLConfig 提供 TiDB 的使用说明
1 parent 42949f5 commit d8583de

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/APIJSONApplication.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
import org.springframework.boot.SpringApplication;
1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
20+
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
1921
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
2023
import org.springframework.web.cors.CorsConfiguration;
2124
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
2225
import org.springframework.web.filter.CorsFilter;
@@ -25,6 +28,7 @@
2528
/**application
2629
* @author Lemon
2730
*/
31+
@Configuration
2832
@SpringBootApplication
2933
public class APIJSONApplication {
3034

@@ -40,7 +44,7 @@ public static void main(String[] args) throws Exception {
4044
}
4145
System.out.println("\n完成测试:远程函数 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
4246

43-
47+
4448
System.out.println("\n\n\n开始测试:请求校验 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
4549
try {
4650
StructureUtil.test();
@@ -53,6 +57,16 @@ public static void main(String[] args) throws Exception {
5357
}
5458

5559

60+
@Bean
61+
public EmbeddedServletContainerCustomizer containerCustomizer() {
62+
return new EmbeddedServletContainerCustomizer() {
63+
64+
@Override
65+
public void customize(ConfigurableEmbeddedServletContainer container) {
66+
container.setPort(8080); //自定义端口号,如果和 TiDB 等其它程序端口有冲突,可改为 8081, 9090, 9091 等未被占用的端口
67+
}
68+
};
69+
}
5670

5771
//支持JavaScript跨域请求<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
5872
/**

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/DemoSQLConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929

3030
/**SQL配置
31+
* TiDB 用法和 MySQL 一致
3132
* @author Lemon
3233
*/
3334
public class DemoSQLConfig extends AbstractSQLConfig {
@@ -41,7 +42,7 @@ public class DemoSQLConfig extends AbstractSQLConfig {
4142

4243
@Override
4344
public String getDBUri() {
44-
//TODO 改成你自己的
45+
//TODO 改成你自己的,TiDB 默认端口为 4000
4546
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? "jdbc:postgresql://localhost:5432/postgres" : "jdbc:mysql://localhost:3306";
4647
}
4748
@Override
@@ -50,7 +51,7 @@ public String getDBAccount() {
5051
}
5152
@Override
5253
public String getDBPassword() {
53-
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? null : "apijson"; //TODO 改成你自己的
54+
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? null : "apijson"; //TODO 改成你自己的,TiDB 默认密码为空字符串 ""
5455
}
5556
@Override
5657
public String getSchema() {

0 commit comments

Comments
 (0)