Skip to content

Commit

Permalink
perf($Exception): refine global exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
钟俊 committed Jan 26, 2021
1 parent bc21a41 commit dae962b
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 159 deletions.
6 changes: 0 additions & 6 deletions exercise-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-security</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
6 changes: 0 additions & 6 deletions muscle-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-security</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,45 @@ public void postConstruct() {

@Bean
public WebFluxConfiguration webFluxConfiguration() {
log.warn("Initial bean: {}", WebFluxConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", WebFluxConfiguration.class.getSimpleName());
return new WebFluxConfiguration();
}

@Bean
@ConditionalOnMissingBean
public MafConfiguration mafConfiguration() {
log.warn("Initial bean: {}", MafConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", MafConfiguration.class.getSimpleName());
return new MafConfiguration();
}

@Bean
@ConditionalOnMissingBean
public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) {
log.warn("Initial bean: {}", AccessLogFilter.class.getSimpleName());
log.warn("Initial bean: '{}'", AccessLogFilter.class.getSimpleName());
return new AccessLogFilter(mafConfiguration);
}

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

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

@Bean
public CommonService commonService(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", CommonServiceImpl.class.getSimpleName());
log.warn("Initial bean: '{}'", CommonServiceImpl.class.getSimpleName());
return new CommonServiceImpl(mafProjectProperty);
}

@Bean
public CommonController commonController(CommonService commonService) {
log.warn("Initial bean: {}", CommonController.class.getSimpleName());
log.warn("Initial bean: '{}'", CommonController.class.getSimpleName());
return new CommonController(commonService);
}
}
6 changes: 0 additions & 6 deletions service-registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
6 changes: 0 additions & 6 deletions spring-boot-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate;
import org.springframework.messaging.MessageHandler;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import springfox.documentation.builders.PathSelectors;
Expand Down Expand Up @@ -80,58 +82,58 @@ public void postConstruct() {
@Bean
@ConditionalOnMissingBean
public MafConfiguration mafConfiguration() {
log.warn("Initial bean: {}", MafConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", MafConfiguration.class.getSimpleName());
val mafConfiguration = new MafConfiguration();
log.warn("{}", mafConfiguration);
return mafConfiguration;
}

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

@Bean
@ConditionalOnMissingBean
public ExceptionControllerAdvice exceptionControllerAdvice() {
log.warn("Initial bean: {}", ExceptionControllerAdvice.class.getSimpleName());
log.warn("Initial bean: '{}'", ExceptionControllerAdvice.class.getSimpleName());
return new ExceptionControllerAdvice();
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "maf.configuration.web-request-log-disabled", havingValue = "false")
public WebRequestLogAspect webRequestLogAspect() {
log.warn("Initial bean: {}", WebRequestLogAspect.class.getSimpleName());
log.warn("Initial bean: '{}'", WebRequestLogAspect.class.getSimpleName());
return new WebRequestLogAspect();
}

@Bean
@ConditionalOnMissingBean
public RedirectController redirectController() {
log.warn("Initial bean: {}", RedirectController.class.getSimpleName());
log.warn("Initial bean: '{}'", RedirectController.class.getSimpleName());
return new RedirectController();
}

@Bean
@ConditionalOnMissingBean
public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) {
log.warn("Initial bean: {}", AccessLogFilter.class.getSimpleName());
log.warn("Initial bean: '{}'", AccessLogFilter.class.getSimpleName());
return new AccessLogFilter(mafConfiguration);
}

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

@Bean
@ConditionalOnMissingBean
public WebMvcConfiguration webMvcConfiguration() {
log.warn("Initial bean: {}", WebMvcConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", WebMvcConfiguration.class.getSimpleName());
return new WebMvcConfiguration();
}

Expand All @@ -140,34 +142,34 @@ public WebMvcConfiguration webMvcConfiguration() {
public GlobalErrorController globalErrorController(ErrorAttributes errorAttributes,
ServerProperties serverProperties,
List<ErrorViewResolver> errorViewResolvers) {
log.warn("Initial bean: {}", GlobalErrorController.class.getSimpleName());
log.warn("Initial bean: '{}'", GlobalErrorController.class.getSimpleName());
return new GlobalErrorController(errorAttributes, serverProperties, errorViewResolvers);
}

@Bean
public HttpApiScanHelper httpApiScanHelper(RequestMappingHandlerMapping requestMappingHandlerMapping) {
log.warn("Initial bean: {}", HttpApiScanHelper.class.getSimpleName());
log.warn("Initial bean: '{}'", HttpApiScanHelper.class.getSimpleName());
return new HttpApiScanHelper(requestMappingHandlerMapping);
}

@Bean
public HttpApiResourceRemoteApiController httpApiResourceRemoteController(MafConfiguration mafConfiguration,
HttpApiScanHelper httpApiScanHelper) {
log.warn("Initial bean: {}", HttpApiResourceRemoteApiController.class.getSimpleName());
log.warn("Initial bean: '{}'", HttpApiResourceRemoteApiController.class.getSimpleName());
return new HttpApiResourceRemoteApiController(mafConfiguration, httpApiScanHelper);
}

@Bean
@ConditionalOnProperty(value = "maf.configuration.swagger-disabled", havingValue = "false")
public Swagger2Configuration swagger2Configuration(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", Swagger2Configuration.class.getSimpleName());
log.warn("Initial bean: '{}'", Swagger2Configuration.class.getSimpleName());
return new Swagger2Configuration(mafProjectProperty);
}

@Bean
@ConditionalOnProperty(value = "maf.configuration.swagger-disabled", havingValue = "false")
public Docket docket(Swagger2Configuration swagger2Configuration, MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", Docket.class.getSimpleName());
log.warn("Initial bean: '{}'", Docket.class.getSimpleName());
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(swagger2Configuration.apiInfo())
.select()
Expand All @@ -178,56 +180,56 @@ public Docket docket(Swagger2Configuration swagger2Configuration, MafProjectProp

@Bean
public CommonService commonService(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", CommonServiceImpl.class.getSimpleName());
log.warn("Initial bean: '{}'", CommonServiceImpl.class.getSimpleName());
return new CommonServiceImpl(mafProjectProperty);
}

@Bean
public CommonController commonController(CommonService commonService) {
log.warn("Initial bean: {}", CommonController.class.getSimpleName());
log.warn("Initial bean: '{}'", CommonController.class.getSimpleName());
return new CommonController(commonService);
}

@Bean
public JwtConfiguration jwtConfiguration(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", JwtConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", JwtConfiguration.class.getSimpleName());
return new JwtConfiguration(mafProjectProperty);
}

@Bean
public DruidConfiguration druidConfiguration(MafConfiguration mafConfiguration) {
log.warn("Initial bean: {}", DruidConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", DruidConfiguration.class.getSimpleName());
return new DruidConfiguration(mafConfiguration);
}

@Bean
public MyBatisPlusConfiguration myBatisPlusConfiguration() {
log.warn("Initial bean: {}", MyBatisPlusConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", MyBatisPlusConfiguration.class.getSimpleName());
return new MyBatisPlusConfiguration();
}

@Bean
public RedisCachingConfiguration redisCachingConfiguration(RedisConnectionFactory redisConnectionFactory) {
log.warn("Initial bean: {}", RedisCachingConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", RedisCachingConfiguration.class.getSimpleName());
return new RedisCachingConfiguration(redisConnectionFactory);
}

@Bean
public RedisConfiguration redisConfiguration(ObjectMapper objectMapper) {
log.warn("Initial bean: {}", RedisConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", RedisConfiguration.class.getSimpleName());
return new RedisConfiguration(objectMapper);
}

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
log.warn("Initial bean: {}", RestTemplate.class.getSimpleName());
log.warn("Initial bean: '{}'", RestTemplate.class.getSimpleName());
return new RestTemplate();
}

@Bean
public SftpClientConfiguration sftpClientConfiguration() {
log.warn("Initial bean: {}", SftpClientConfiguration.class.getSimpleName());
log.warn("Initial bean: '{}'", SftpClientConfiguration.class.getSimpleName());
return new SftpClientConfiguration();
}

Expand All @@ -247,6 +249,7 @@ public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(SftpClientConfigur
// We return a caching session factory, so that we don't have to reconnect to SFTP server for each time
val cachingSessionFactory = new CachingSessionFactory<>(factory, sftpClientConfiguration.getSessionCacheSize());
cachingSessionFactory.setSessionWaitTimeout(sftpClientConfiguration.getSessionWaitTimeout());
log.warn("Initial bean: '{}'", cachingSessionFactory.getClass().getSimpleName());
return cachingSessionFactory;
}

Expand All @@ -264,6 +267,7 @@ public MessageHandler messageHandler(SessionFactory<ChannelSftp.LsEntry> sftpSes
throw new IllegalArgumentException("File expected as payload.");
}
});
log.warn("Initial bean: '{}'", handler.getClass().getSimpleName());
return handler;
}

Expand All @@ -276,19 +280,32 @@ public SftpRemoteFileTemplate sftpRemoteFileTemplate(SessionFactory<ChannelSftp.
sftpRemoteFileTemplate.setAutoCreateDirectory(true);
// sftpRemoteFileTemplate.setBeanFactory(beanFactory);
sftpRemoteFileTemplate.afterPropertiesSet();
log.warn("Initial bean: '{}'", sftpRemoteFileTemplate.getClass().getSimpleName());
return sftpRemoteFileTemplate;
}

@Bean
public SftpSubDirectoryRunner sftpSubDirectoryRunner(SftpRemoteFileTemplate sftpRemoteFileTemplate,
SftpClientConfiguration sftpClientConfiguration) {
log.warn("Initial bean: {}", SftpSubDirectoryRunner.class.getSimpleName());
log.warn("Initial bean: '{}'", SftpSubDirectoryRunner.class.getSimpleName());
return new SftpSubDirectoryRunner(sftpRemoteFileTemplate, sftpClientConfiguration);
}

@Bean
public SftpHelper sftpHelper(SftpRemoteFileTemplate sftpRemoteFileTemplate) {
log.warn("Initial bean: {}", SftpHelper.class.getSimpleName());
log.warn("Initial bean: '{}'", SftpHelper.class.getSimpleName());
return new SftpHelperImpl(sftpRemoteFileTemplate);
}

@Bean
public WebSecurityConfiguration webSecurityConfiguration() {
log.warn("Initial bean: '{}'", WebSecurityConfiguration.class.getSimpleName());
return new WebSecurityConfiguration();
}

@Bean
public BCryptPasswordEncoder bcryptPasswordEncoder() {
log.warn("Initial bean: '{}'", BCryptPasswordEncoder.class.getSimpleName());
return new BCryptPasswordEncoder();
}
}
Loading

0 comments on commit dae962b

Please sign in to comment.