Skip to content

Commit

Permalink
Server: Demo 支持自定义端口号;DemoSQLConfig 提供 TiDB 的使用说明
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Dec 20, 2018
1 parent 42949f5 commit d8583de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Expand Up @@ -16,7 +16,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
Expand All @@ -25,6 +28,7 @@
/**application
* @author Lemon
*/
@Configuration
@SpringBootApplication
public class APIJSONApplication {

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


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


@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return new EmbeddedServletContainerCustomizer() {

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(8080); //自定义端口号,如果和 TiDB 等其它程序端口有冲突,可改为 8081, 9090, 9091 等未被占用的端口
}
};
}

//支持JavaScript跨域请求<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/**
Expand Down
Expand Up @@ -28,6 +28,7 @@


/**SQL配置
* TiDB 用法和 MySQL 一致
* @author Lemon
*/
public class DemoSQLConfig extends AbstractSQLConfig {
Expand All @@ -41,7 +42,7 @@ public class DemoSQLConfig extends AbstractSQLConfig {

@Override
public String getDBUri() {
//TODO 改成你自己的
//TODO 改成你自己的,TiDB 默认端口为 4000
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? "jdbc:postgresql://localhost:5432/postgres" : "jdbc:mysql://localhost:3306";
}
@Override
Expand All @@ -50,7 +51,7 @@ public String getDBAccount() {
}
@Override
public String getDBPassword() {
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? null : "apijson"; //TODO 改成你自己的
return DATABASE_POSTGRESQL.equalsIgnoreCase(getDatabase()) ? null : "apijson"; //TODO 改成你自己的,TiDB 默认密码为空字符串 ""
}
@Override
public String getSchema() {
Expand Down

0 comments on commit d8583de

Please sign in to comment.