Skip to content

Commit

Permalink
feat($Starter): abstract startup analysis
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
johnnymillergh committed Feb 10, 2021
1 parent c4e9899 commit 0802aa2
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.jmsoftware.maf.reactivespringcloudstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.reactivespringcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.reactivespringcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.util.StopWatch;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -23,27 +25,16 @@
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGatewayApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public ApiGatewayApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
ApiGatewayApplication.mafProjectProperty = mafProjectProperty;
ApiGatewayApplication.ipHelper = ipHelper;
public ApiGatewayApplication(SpringBootStartupHelper springBootStartupHelper) {
ApiGatewayApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
val startInstant = Instant.now();
STOP_WATCH.start();
SpringApplication.run(ApiGatewayApplication.class, args);
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
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, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getBaseUrl(), mafProjectProperty.getContextPath());
springBootStartupHelper.stop(STOP_WATCH);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.jmsoftware.maf.authcenter;

import com.jmsoftware.maf.springcloudstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.time.Duration;
import java.time.Instant;
import java.util.TimeZone;
import org.springframework.util.StopWatch;

/**
* <h1>AuthCenterApplication</h1>
Expand All @@ -26,27 +21,16 @@
@EnableDiscoveryClient
@SpringBootApplication
public class AuthCenterApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public AuthCenterApplication(MafProjectProperty projectProperty, IpHelper ipHelper) {
AuthCenterApplication.mafProjectProperty = projectProperty;
AuthCenterApplication.ipHelper = ipHelper;
public AuthCenterApplication(SpringBootStartupHelper springBootStartupHelper) {
AuthCenterApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
val startInstant = Instant.now();
STOP_WATCH.start();
SpringApplication.run(AuthCenterApplication.class, args);
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
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: http://{}:{}{}/",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
springBootStartupHelper.stop(STOP_WATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ private void init() {
secretKey = Keys.hmacShaKeyFor(jwtConfiguration.getSigningKey().getBytes(StandardCharsets.UTF_8));
log.warn("Secret key for JWT was generated. Algorithm: {}", secretKey.getAlgorithm());
jwtParser = Jwts.parserBuilder().setSigningKey(secretKey).build();
// redisTemplate.setKeySerializer(new StringRedisSerializer());
// redisTemplate.setValueSerializer(new StringRedisSerializer());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.jmsoftware.maf.exercisemis;

import com.jmsoftware.maf.springcloudstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.time.Duration;
import java.time.Instant;
import java.util.TimeZone;
import org.springframework.util.StopWatch;

/**
* <h1>ExerciseMisApplication</h1>
Expand All @@ -26,27 +21,16 @@
@EnableDiscoveryClient
@SpringBootApplication
public class ExerciseMisApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public ExerciseMisApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
ExerciseMisApplication.mafProjectProperty = mafProjectProperty;
ExerciseMisApplication.ipHelper = ipHelper;
public ExerciseMisApplication(SpringBootStartupHelper springBootStartupHelper) {
ExerciseMisApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
val startInstant = Instant.now();
STOP_WATCH.start();
SpringApplication.run(ExerciseMisApplication.class, args);
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
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: http://{}:{}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
springBootStartupHelper.stop(STOP_WATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.jmsoftware.maf.springcloudstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.util.StopWatch;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -26,27 +28,16 @@
@EnableDiscoveryClient
@SpringBootApplication
public class MuscleMisApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public MuscleMisApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
MuscleMisApplication.mafProjectProperty = mafProjectProperty;
MuscleMisApplication.ipHelper = ipHelper;
public MuscleMisApplication(SpringBootStartupHelper springBootStartupHelper) {
MuscleMisApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
val startInstant = Instant.now();
STOP_WATCH.start();
SpringApplication.run(MuscleMisApplication.class, args);
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
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: http://{}:{}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
springBootStartupHelper.stop(STOP_WATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.jmsoftware.maf.reactivespringcloudstarter.controller.CommonController;
import com.jmsoftware.maf.reactivespringcloudstarter.filter.AccessLogFilter;
import com.jmsoftware.maf.reactivespringcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.reactivespringcloudstarter.helper.SpringBootStartupHelper;
import com.jmsoftware.maf.reactivespringcloudstarter.service.CommonService;
import com.jmsoftware.maf.reactivespringcloudstarter.service.impl.CommonServiceImpl;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -74,6 +75,13 @@ public IpHelper ipHelper(MafProjectProperty mafProjectProperty) {
return new IpHelper(mafProjectProperty);
}

@Bean
public SpringBootStartupHelper springBootStartupHelper(MafProjectProperty mafProjectProperty,
IpHelper ipHelper) {
log.warn("Initial bean: '{}'", SpringBootStartupHelper.class.getSimpleName());
return new SpringBootStartupHelper(mafProjectProperty, ipHelper);
}

@Bean
public CommonService commonService(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: '{}'", CommonServiceImpl.class.getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jmsoftware.maf.reactivespringcloudstarter.helper;

import com.jmsoftware.maf.reactivespringcloudstarter.configuration.MafProjectProperty;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import java.time.Instant;
import java.time.ZoneId;
import java.util.TimeZone;

/**
* Description: SpringBootStartupHelper, change description here.
*
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 2/10/2021 10:07 AM
**/
@Slf4j
@Component
@RequiredArgsConstructor
public class SpringBootStartupHelper {
private static final String LINE_SEPARATOR = System.lineSeparator();
private final MafProjectProperty mafProjectProperty;
private final IpHelper ipHelper;

public void stop(@NonNull StopWatch stopWatch) {
stopWatch.stop();
log.info("🥳 Congratulations! 🎉");
log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion());
log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment());
log.info("⏳ Deployment duration: {} seconds ({} ms)", stopWatch.getTotalTimeSeconds(),
stopWatch.getTotalTimeMillis());
log.info("⏰ App started at {} (timezone - {})", Instant.now().atZone(ZoneId.of("UTC+8")), TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: http://{}:{}{}/",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.jmsoftware.maf.springcloudstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.util.StopWatch;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -26,27 +28,16 @@
@EnableDiscoveryClient
@SpringBootApplication
public class SpringBootAdminApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public SpringBootAdminApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
SpringBootAdminApplication.mafProjectProperty = mafProjectProperty;
SpringBootAdminApplication.ipHelper = ipHelper;
public SpringBootAdminApplication(SpringBootStartupHelper springBootStartupHelper) {
SpringBootAdminApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
val startInstant = Instant.now();
STOP_WATCH.start();
SpringApplication.run(SpringBootAdminApplication.class, args);
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
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: http://{}:{}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
springBootStartupHelper.stop(STOP_WATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.jmsoftware.maf.springcloudstarter.filter.AccessLogFilter;
import com.jmsoftware.maf.springcloudstarter.helper.HttpApiScanHelper;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import com.jmsoftware.maf.springcloudstarter.redis.RedisConfiguration;
import com.jmsoftware.maf.springcloudstarter.service.CommonService;
import com.jmsoftware.maf.springcloudstarter.service.impl.CommonServiceImpl;
Expand Down Expand Up @@ -91,12 +92,18 @@ public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) {
}

@Bean
@ConditionalOnMissingBean
public IpHelper ipHelper(Environment environment) {
log.warn("Initial bean: '{}'", IpHelper.class.getSimpleName());
return new IpHelper(environment);
}

@Bean
public SpringBootStartupHelper springBootStartupHelper(MafProjectProperty mafProjectProperty,
IpHelper ipHelper) {
log.warn("Initial bean: '{}'", SpringBootStartupHelper.class.getSimpleName());
return new SpringBootStartupHelper(mafProjectProperty, ipHelper);
}

@Bean
@ConditionalOnMissingBean
public WebMvcConfiguration webMvcConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jmsoftware.maf.springcloudstarter.helper;

import com.jmsoftware.maf.springcloudstarter.configuration.MafProjectProperty;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import java.time.Instant;
import java.time.ZoneId;
import java.util.TimeZone;

/**
* Description: SpringBootStartupHelper, change description here.
*
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 2/10/2021 10:07 AM
**/
@Slf4j
@Component
@RequiredArgsConstructor
public class SpringBootStartupHelper {
private static final String LINE_SEPARATOR = System.lineSeparator();
private final MafProjectProperty mafProjectProperty;
private final IpHelper ipHelper;

public void stop(@NonNull StopWatch stopWatch) {
stopWatch.stop();
log.info("🥳 Congratulations! 🎉");
log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion());
log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment());
log.info("⏳ Deployment duration: {} seconds ({} ms)", stopWatch.getTotalTimeSeconds(),
stopWatch.getTotalTimeMillis());
log.info("⏰ App started at {} (timezone - {})", Instant.now().atZone(ZoneId.of("UTC+8")), TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: http://{}:{}{}/",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
}
}

0 comments on commit 0802aa2

Please sign in to comment.