mirror of https://github.com/longtai-cn/hippo4j
parent
483e3dd636
commit
bbb10ee4c9
@ -0,0 +1,19 @@
|
||||
package cn.hippo4j.starter.core;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
/**
|
||||
* Config empty analyzer.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/28 21:59
|
||||
*/
|
||||
public class ConfigEmptyAnalyzer extends AbstractFailureAnalyzer<ConfigEmptyException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, ConfigEmptyException cause) {
|
||||
return new FailureAnalysis(cause.getDescription(), cause.getAction(), cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.hippo4j.starter.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Config empty exception.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/28 21:58
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ConfigEmptyException extends RuntimeException {
|
||||
|
||||
private String description;
|
||||
|
||||
private String action;
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package cn.hippo4j.starter.enable;
|
||||
|
||||
import cn.hippo4j.starter.config.BootstrapProperties;
|
||||
import cn.hippo4j.starter.core.ConfigEmptyException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
/**
|
||||
* Before check configuration.
|
||||
*
|
||||
* @author chen.ma
|
||||
* @date 2021/11/28 22:44
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class BeforeCheckConfiguration {
|
||||
|
||||
@Bean
|
||||
public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(BootstrapProperties properties, ConfigurableEnvironment environment) {
|
||||
String namespace = properties.getNamespace();
|
||||
if (StrUtil.isBlank(namespace)) {
|
||||
throw new ConfigEmptyException(
|
||||
"Web server failed to start. The dynamic thread pool namespace is empty.",
|
||||
"Please check whether the [spring.dynamic.thread-pool.namespace] configuration is empty or an empty string."
|
||||
);
|
||||
}
|
||||
|
||||
String itemId = properties.getItemId();
|
||||
if (StrUtil.isBlank(itemId)) {
|
||||
throw new ConfigEmptyException(
|
||||
"Web server failed to start. The dynamic thread pool item id is empty.",
|
||||
"Please check whether the [spring.dynamic.thread-pool.item-id] configuration is empty or an empty string."
|
||||
);
|
||||
}
|
||||
|
||||
String serverAddr = properties.getServerAddr();
|
||||
if (StrUtil.isBlank(serverAddr)) {
|
||||
throw new ConfigEmptyException(
|
||||
"Web server failed to start. The dynamic thread pool server addr is empty.",
|
||||
"Please check whether the [spring.dynamic.thread-pool.server-addr] configuration is empty or an empty string."
|
||||
);
|
||||
}
|
||||
|
||||
String applicationName = environment.getProperty("spring.application.name");
|
||||
if (StrUtil.isBlank(applicationName)) {
|
||||
throw new ConfigEmptyException(
|
||||
"Web server failed to start. The dynamic thread pool application name is empty.",
|
||||
"Please check whether the [spring.application.name] configuration is empty or an empty string."
|
||||
);
|
||||
}
|
||||
|
||||
return new BeforeCheckConfiguration.BeforeCheck();
|
||||
}
|
||||
|
||||
public class BeforeCheck {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=cn.hippo4j.starter.core.ConfigEmptyAnalyzer
|
||||
|
Loading…
Reference in new issue