Skip to content

Commit 43885c9

Browse files
author
zhangrongfan
committed
Improve environment querying
1 parent 098717a commit 43885c9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

mybatis-boost-spring-boot-autoconfigure/src/main/java/cn/mybatisboost/spring/boot/autoconfigure/EnvironmentHolder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class EnvironmentHolder implements EnvironmentPostProcessor {
1010

1111
public static ConfigurableEnvironment getEnvironment() {
1212
if (environment == null) {
13-
throw new Error("Environment haven't been set yet");
13+
throw new EnvironmentNotSetError("Environment haven't been set yet");
1414
}
1515
return environment;
1616
}
@@ -19,4 +19,11 @@ public static ConfigurableEnvironment getEnvironment() {
1919
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
2020
EnvironmentHolder.environment = environment;
2121
}
22+
23+
public static class EnvironmentNotSetError extends Error {
24+
25+
EnvironmentNotSetError(String message) {
26+
super(message);
27+
}
28+
}
2229
}

mybatis-boost-spring-boot-autoconfigure/src/main/java/cn/mybatisboost/spring/boot/autoconfigure/NosqlConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
public class NosqlConfiguration implements ImportBeanDefinitionRegistrar {
1414

1515
private static Logger logger = LoggerFactory.getLogger(NosqlConfiguration.class);
16-
private static boolean mapUnderscoreToCamelCase = EnvironmentHolder.getEnvironment()
17-
.getProperty("mybatis.configuration.map-underscore-to-camel-case", boolean.class, false);
16+
private static boolean mapUnderscoreToCamelCase;
1817

1918
static {
19+
try {
20+
mapUnderscoreToCamelCase = EnvironmentHolder.getEnvironment()
21+
.getProperty("mybatis.configuration.map-underscore-to-camel-case",
22+
boolean.class, false);
23+
} catch (EnvironmentHolder.EnvironmentNotSetError e) {
24+
logger.info("Use default mapUnderscoreToCamelCase value", e);
25+
}
2026
try {
2127
CtClass ctClass = ClassPool.getDefault().get("org.mybatis.spring.mapper.ClassPathMapperScanner");
2228
ctClass.getDeclaredMethod("checkCandidate").insertAfter("if ($_) " +

0 commit comments

Comments
 (0)