feat:多环境配置
This commit is contained in:
parent
6841e2c7da
commit
3b12e9ece2
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.example.admin_server.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
public class AppConfig {
|
||||||
|
/**
|
||||||
|
* 环境
|
||||||
|
*/
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String env;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境名称
|
||||||
|
*/
|
||||||
|
@Value("${app.env-name}")
|
||||||
|
private String envName;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.example.admin_server.controller.admin;
|
package com.example.admin_server.controller.admin;
|
||||||
|
|
||||||
|
import com.example.admin_server.config.AppConfig;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -9,11 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/admin")
|
@RequestMapping("/api/admin")
|
||||||
@Tag(name = "AdminMain")
|
@Tag(name = "AdminMain")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class AdminMainController {
|
public class AdminMainController {
|
||||||
|
|
||||||
|
private final AppConfig appConfig;
|
||||||
|
|
||||||
@GetMapping("/welcome")
|
@GetMapping("/welcome")
|
||||||
@Operation(summary = "Hello admin")
|
@Operation(summary = "Hello admin")
|
||||||
public String welcome(){
|
public String welcome() {
|
||||||
return "Hello admin";
|
return "Hello admin" + appConfig.getEnvName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.example.admin_server.controller.client;
|
package com.example.admin_server.controller.client;
|
||||||
|
|
||||||
|
import com.example.admin_server.config.AppConfig;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -9,11 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/client")
|
@RequestMapping("/api/client")
|
||||||
@Tag(name = "ClientMain")
|
@Tag(name = "ClientMain")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class ClientMainController {
|
public class ClientMainController {
|
||||||
|
|
||||||
|
private final AppConfig appConfig;
|
||||||
|
|
||||||
@GetMapping("/welcome")
|
@GetMapping("/welcome")
|
||||||
@Operation(summary = "Hello client")
|
@Operation(summary = "Hello client")
|
||||||
public String welcome(){
|
public String welcome(){
|
||||||
return "Hello client";
|
return "Hello client" + appConfig.getEnvName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.example.admin_server.controller.employee;
|
package com.example.admin_server.controller.employee;
|
||||||
|
|
||||||
|
import com.example.admin_server.config.AppConfig;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
@ -9,11 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/employee")
|
@RequestMapping("/api/employee")
|
||||||
@Tag(name = "EmployeeMain", description = "welcome")
|
@Tag(name = "EmployeeMain", description = "welcome")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class EmployeeMainController {
|
public class EmployeeMainController {
|
||||||
|
|
||||||
|
private final AppConfig appConfig;
|
||||||
|
|
||||||
@GetMapping("/welcome")
|
@GetMapping("/welcome")
|
||||||
@Operation(summary = "Hello employee")
|
@Operation(summary = "Hello employee")
|
||||||
public String welcome() {
|
public String welcome() {
|
||||||
return "Hello employee";
|
return "Hello employee" + appConfig.getEnvName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
# application.yml (公用配置)
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: my-app
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/admin_server?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||||
|
username: admin_server
|
||||||
|
password: iyzHSPYE3DzEThsY
|
||||||
|
|
||||||
|
app:
|
||||||
|
env-name: 'dev'
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
swagger-ui:
|
||||||
|
path: /swagger-ui.html
|
||||||
|
tags-sorter: alpha
|
||||||
|
operations-sorter: alpha
|
||||||
|
api-docs:
|
||||||
|
path: /v3/api-docs
|
||||||
|
group-configs:
|
||||||
|
- group: '管理端'
|
||||||
|
paths-to-match: '/api/admin/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.admin
|
||||||
|
- group: '客户端'
|
||||||
|
paths-to-match: '/api/client/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.client
|
||||||
|
- group: '员工端'
|
||||||
|
paths-to-match: '/api/employee/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.employee
|
||||||
|
|
||||||
|
knife4j:
|
||||||
|
enable: true
|
||||||
|
setting:
|
||||||
|
language: zh_cn
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
# application.yml (公用配置)
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: my-app
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/admin_server?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||||
|
username: admin_server
|
||||||
|
password: iyzHSPYE3DzEThsY
|
||||||
|
|
||||||
|
app:
|
||||||
|
env-name: 'prop'
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
swagger-ui:
|
||||||
|
path: /swagger-ui.html
|
||||||
|
tags-sorter: alpha
|
||||||
|
operations-sorter: alpha
|
||||||
|
api-docs:
|
||||||
|
path: /v3/api-docs
|
||||||
|
group-configs:
|
||||||
|
- group: '管理端'
|
||||||
|
paths-to-match: '/api/admin/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.admin
|
||||||
|
- group: '客户端'
|
||||||
|
paths-to-match: '/api/client/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.client
|
||||||
|
- group: '员工端'
|
||||||
|
paths-to-match: '/api/employee/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.employee
|
||||||
|
|
||||||
|
knife4j:
|
||||||
|
enable: true
|
||||||
|
setting:
|
||||||
|
language: zh_cn
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
# application.yml (公用配置)
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: my-app
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://localhost:3306/admin_server?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||||
|
username: admin_server
|
||||||
|
password: iyzHSPYE3DzEThsY
|
||||||
|
|
||||||
|
app:
|
||||||
|
env-name: 'test'
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
swagger-ui:
|
||||||
|
path: /swagger-ui.html
|
||||||
|
tags-sorter: alpha
|
||||||
|
operations-sorter: alpha
|
||||||
|
api-docs:
|
||||||
|
path: /v3/api-docs
|
||||||
|
group-configs:
|
||||||
|
- group: '管理端'
|
||||||
|
paths-to-match: '/api/admin/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.admin
|
||||||
|
- group: '客户端'
|
||||||
|
paths-to-match: '/api/client/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.client
|
||||||
|
- group: '员工端'
|
||||||
|
paths-to-match: '/api/employee/**'
|
||||||
|
packages-to-scan: com.example.admin_server.controller.employee
|
||||||
|
|
||||||
|
knife4j:
|
||||||
|
enable: true
|
||||||
|
setting:
|
||||||
|
language: zh_cn
|
||||||
|
|
||||||
|
|
@ -1,12 +1,25 @@
|
||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8080
|
||||||
|
|
||||||
|
# application.yml (公用配置)
|
||||||
spring:
|
spring:
|
||||||
|
application:
|
||||||
|
name: my-app
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
# 指定当前激活环境
|
||||||
|
profiles:
|
||||||
|
active: test
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://localhost:3306/admin_server?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://localhost:3306/admin_server?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||||
username: admin_server
|
username: admin_server
|
||||||
password: iyzHSPYE3DzEThsY
|
password: iyzHSPYE3DzEThsY
|
||||||
|
|
||||||
|
app:
|
||||||
|
env-name: 'dev'
|
||||||
|
|
||||||
|
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
||||||
path: /swagger-ui.html
|
path: /swagger-ui.html
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue