From aafac56c820fa406f77d6ae0ba6b3c7aba517e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Tue, 29 Dec 2020 13:27:56 +0800 Subject: [PATCH] perf($ReactiveStarter): abstract project property [skip ci] --- .../maf/apigateway/ApiGatewayApplication.java | 16 ++-- .../configuration/JwtConfiguration.java | 9 +- .../configuration/ProjectProperty.java | 40 -------- .../configuration/ServerConfiguration.java | 7 +- .../SwaggerResourceProvider.java | 19 ++-- .../apigateway/universal/package-info.java | 1 - .../service/impl/CommonServiceImpl.java | 6 +- .../src/main/resources/application.yml | 6 +- .../configuration/MafProjectProperty.java | 93 +++++++++++++++++++ .../MafReactiveAutoConfiguration.java | 10 +- 10 files changed, 133 insertions(+), 74 deletions(-) delete mode 100644 api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ProjectProperty.java delete mode 100644 api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/package-info.java create mode 100644 reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafProjectProperty.java diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/ApiGatewayApplication.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/ApiGatewayApplication.java index 8b413632..c71778b9 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/ApiGatewayApplication.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/ApiGatewayApplication.java @@ -1,7 +1,7 @@ package com.jmsoftware.maf.apigateway; -import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty; import com.jmsoftware.maf.apigateway.universal.configuration.ServerConfiguration; +import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.boot.SpringApplication; @@ -28,11 +28,11 @@ @EnableReactiveFeignClients public class ApiGatewayApplication { private static final String LINE_SEPARATOR = System.lineSeparator(); - private static ProjectProperty projectProperty; + private static MafProjectProperty mafProjectProperty; private static ServerConfiguration serverConfiguration; - public ApiGatewayApplication(ProjectProperty projectProperty, ServerConfiguration serverConfiguration) { - ApiGatewayApplication.projectProperty = projectProperty; + public ApiGatewayApplication(MafProjectProperty mafProjectProperty, ServerConfiguration serverConfiguration) { + ApiGatewayApplication.mafProjectProperty = mafProjectProperty; ApiGatewayApplication.serverConfiguration = serverConfiguration; } @@ -42,12 +42,12 @@ public static void main(String[] args) { val endInstant = Instant.now(); val duration = Duration.between(startInstant, endInstant); log.info("🥳 Congratulations! 🎉"); - log.info("🖥 {}@{} started!", projectProperty.getProjectArtifactId(), projectProperty.getVersion()); - log.info("⚙️ Environment: {}", projectProperty.getEnvironment()); + log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion()); + log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment()); log.info("⏳ Deployment duration: {} seconds ({} ms)", duration.getSeconds(), duration.toMillis()); log.info("⏰ App started at {} (timezone - {})", endInstant, TimeZone.getDefault().getDisplayName()); log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: {}/{}", - LINE_SEPARATOR, LINE_SEPARATOR, serverConfiguration.getServerPort(), projectProperty.getContextPath(), - LINE_SEPARATOR, serverConfiguration.getBaseUrl(), projectProperty.getContextPath()); + LINE_SEPARATOR, LINE_SEPARATOR, serverConfiguration.getServerPort(), mafProjectProperty.getContextPath(), + LINE_SEPARATOR, serverConfiguration.getBaseUrl(), mafProjectProperty.getContextPath()); } } diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/security/configuration/JwtConfiguration.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/security/configuration/JwtConfiguration.java index 111fc10b..8c7f6371 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/security/configuration/JwtConfiguration.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/security/configuration/JwtConfiguration.java @@ -1,6 +1,6 @@ package com.jmsoftware.maf.apigateway.security.configuration; -import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty; +import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -27,11 +27,12 @@ public class JwtConfiguration { */ private String jwtRedisKeyPrefix; - public JwtConfiguration(ProjectProperty projectProperty) { - this.signingKey = String.format("%s %s", projectProperty.getProjectParentArtifactId(), projectProperty.getVersion()); + public JwtConfiguration(MafProjectProperty mafProjectProperty) { + this.signingKey = String.format("%s %s", mafProjectProperty.getProjectParentArtifactId(), + mafProjectProperty.getVersion()); log.info("Initiated JWT signing key: {}. The specified key byte array is {} bits", this.signingKey, this.signingKey.getBytes(StandardCharsets.UTF_8).length * 8); - jwtRedisKeyPrefix = String.format("%s:jwt:", projectProperty.getProjectParentArtifactId()); + jwtRedisKeyPrefix = String.format("%s:jwt:", mafProjectProperty.getProjectParentArtifactId()); log.warn("Initiated 'jwtRedisKeyPrefix': {}", jwtRedisKeyPrefix); } diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ProjectProperty.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ProjectProperty.java deleted file mode 100644 index 1dccd83a..00000000 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ProjectProperty.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.jmsoftware.maf.apigateway.universal.configuration; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; -import org.springframework.validation.annotation.Validated; - -/** - *

ProjectProperty

- *

- * Change description here. - * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2019-04-18 13:01 - **/ -@Data -@Validated -@Component -@SuppressWarnings("jol") -@ConfigurationProperties(prefix = "project.property") -public class ProjectProperty { - private String basePackage; - private String contextPath; - private String groupId; - private String projectParentArtifactId; - private String projectArtifactId; - private String version; - private String description; - private String jdkVersion; - private String environment; - private String url; - private String inceptionYear; - private String organizationName; - private String organizationUrl; - private String issueManagementSystem; - private String issueManagementUrl; - private String developerName; - private String developerEmail; - private String developerUrl; -} diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ServerConfiguration.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ServerConfiguration.java index 4af26b12..973d8c42 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ServerConfiguration.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/ServerConfiguration.java @@ -1,5 +1,6 @@ package com.jmsoftware.maf.apigateway.universal.configuration; +import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,7 +31,7 @@ @RequiredArgsConstructor public class ServerConfiguration implements ApplicationListener { private static final String DEVELOPMENT_ENVIRONMENT = "development"; - private final ProjectProperty projectProperty; + private final MafProjectProperty mafProjectProperty; private int serverPort; @Override @@ -51,7 +52,7 @@ public void onApplicationEvent(WebServerInitializedEvent event) { * @date 2019-05-03 16:05 */ public String getBaseUrl() { - return "http://" + this.getPublicIp() + ":" + serverPort + projectProperty.getContextPath(); + return "http://" + this.getPublicIp() + ":" + serverPort + mafProjectProperty.getContextPath(); } /** @@ -60,7 +61,7 @@ public String getBaseUrl() { * @return public IP */ public String getPublicIp() { - if (projectProperty.getEnvironment().contains(DEVELOPMENT_ENVIRONMENT)) { + if (mafProjectProperty.getEnvironment().contains(DEVELOPMENT_ENVIRONMENT)) { return this.getInternetIp(); } try { diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/SwaggerResourceProvider.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/SwaggerResourceProvider.java index 05b9537f..2366b20b 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/SwaggerResourceProvider.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/configuration/SwaggerResourceProvider.java @@ -1,5 +1,6 @@ package com.jmsoftware.maf.apigateway.universal.configuration; +import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -40,7 +41,7 @@ public class SwaggerResourceProvider implements SwaggerResourcesProvider { private static final String SWAGGER_API_URI = "/v2/api-docs"; private static final String LINE_SEPARATOR = System.lineSeparator(); - private final ProjectProperty projectProperty; + private final MafProjectProperty mafProjectProperty; private final RouteLocator routeLocator; /** @@ -72,26 +73,26 @@ public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() - .apis(RequestHandlerSelectors.basePackage(projectProperty.getBasePackage())) + .apis(RequestHandlerSelectors.basePackage(mafProjectProperty.getBasePackage())) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { - val projectArtifactId = projectProperty.getProjectArtifactId(); - val version = projectProperty.getVersion(); - val developerEmail = projectProperty.getDeveloperEmail(); - val developerUrl = projectProperty.getDeveloperUrl(); + val projectArtifactId = mafProjectProperty.getProjectArtifactId(); + val version = mafProjectProperty.getVersion(); + val developerEmail = mafProjectProperty.getDeveloperEmail(); + val developerUrl = mafProjectProperty.getDeveloperUrl(); return new ApiInfoBuilder() .title(String.format("API for %s@%s", projectArtifactId, version)) .description(String.format("%s %sArtifact ID: %s%sEnvironment: %s", - projectProperty.getDescription(), + mafProjectProperty.getDescription(), LINE_SEPARATOR, projectArtifactId, LINE_SEPARATOR, - projectProperty.getEnvironment())) + mafProjectProperty.getEnvironment())) .contact(new Contact(String.format("%s, email: %s%sHome page: %s", - projectProperty.getDeveloperName(), + mafProjectProperty.getDeveloperName(), developerEmail, LINE_SEPARATOR, developerUrl), diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/package-info.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/package-info.java deleted file mode 100644 index b25c5d73..00000000 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.jmsoftware.maf.apigateway.universal; diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/service/impl/CommonServiceImpl.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/service/impl/CommonServiceImpl.java index 7e693d66..1fe81a87 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/service/impl/CommonServiceImpl.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/service/impl/CommonServiceImpl.java @@ -1,8 +1,8 @@ package com.jmsoftware.maf.apigateway.universal.service.impl; -import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty; import com.jmsoftware.maf.apigateway.universal.service.CommonService; import com.jmsoftware.maf.common.domain.ValidationTestPayload; +import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -27,12 +27,12 @@ @Service @RequiredArgsConstructor public class CommonServiceImpl implements CommonService { - private final ProjectProperty projectProperty; + private final MafProjectProperty mafProjectProperty; @Override public Map getApplicationInfo() { var map = new HashMap(16); - var fieldsInfo = getFieldsInfo(projectProperty); + var fieldsInfo = getFieldsInfo(mafProjectProperty); fieldsInfo.forEach(fieldInfo -> { var type = fieldInfo.get("type"); if ("class java.lang.String".equals(type)) { diff --git a/api-gateway/src/main/resources/application.yml b/api-gateway/src/main/resources/application.yml index 874e7548..9bc74fd6 100644 --- a/api-gateway/src/main/resources/application.yml +++ b/api-gateway/src/main/resources/application.yml @@ -72,8 +72,8 @@ logging: com.jmsoftware: DEBUG # org.springframework.cloud.gateway: debug -project: - property: +maf: + project-property: base-package: @project.groupId@ context-path: group-id: @project.groupId@ @@ -92,8 +92,6 @@ project: developer-name: @developerName@ developer-email: @developerEmail@ developer-url: @developerUrl@ - -maf: configuration: ignored-url: post: diff --git a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafProjectProperty.java b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafProjectProperty.java new file mode 100644 index 00000000..d32e7f99 --- /dev/null +++ b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafProjectProperty.java @@ -0,0 +1,93 @@ +package com.jmsoftware.maf.reactivespringbootstarter.configuration; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +/** + *

MafProjectProperty

+ *

+ * M&F project property, containing the basic constants of the project. + * + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 12/29/2020 1:21 PM + */ +@Data +@Validated +@Component +@SuppressWarnings("jol") +@ConfigurationProperties(prefix = "maf.project-property") +public class MafProjectProperty { + /** + * The Base package. + */ + private String basePackage; + /** + * The Context path. + */ + private String contextPath; + /** + * The Group id. + */ + private String groupId; + /** + * The Project parent artifact id. + */ + private String projectParentArtifactId; + /** + * The Project artifact id. + */ + private String projectArtifactId; + /** + * The Version. + */ + private String version; + /** + * The Description. + */ + private String description; + /** + * The Jdk version. + */ + private String jdkVersion; + /** + * The Environment. + */ + private String environment; + /** + * The Url. + */ + private String url; + /** + * The Inception year. + */ + private String inceptionYear; + /** + * The Organization name. + */ + private String organizationName; + /** + * The Organization url. + */ + private String organizationUrl; + /** + * The Issue management system. + */ + private String issueManagementSystem; + /** + * The Issue management url. + */ + private String issueManagementUrl; + /** + * The Developer name. + */ + private String developerName; + /** + * The Developer email. + */ + private String developerEmail; + /** + * The Developer url. + */ + private String developerUrl; +} diff --git a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafReactiveAutoConfiguration.java b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafReactiveAutoConfiguration.java index 769cce21..5ed087a7 100644 --- a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafReactiveAutoConfiguration.java +++ b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/reactivespringbootstarter/configuration/MafReactiveAutoConfiguration.java @@ -31,14 +31,20 @@ public void postConstruct() { @Bean @ConditionalOnMissingBean public MafConfiguration mafConfiguration() { - log.warn("Initial bean: {}", MafConfiguration.class.getName()); + log.warn("Initial bean: {}", MafConfiguration.class.getSimpleName()); return new MafConfiguration(); } @Bean @ConditionalOnMissingBean public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) { - log.warn("Initial bean: {}", AccessLogFilter.class.getName()); + log.warn("Initial bean: {}", AccessLogFilter.class.getSimpleName()); return new AccessLogFilter(mafConfiguration); } + + @Bean + public MafProjectProperty mafProjectProperty() { + log.warn("Initial bean: {}", MafProjectProperty.class.getSimpleName()); + return new MafProjectProperty(); + } }