diff --git a/pom.xml b/pom.xml index 9f8962c5..c2b2101f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ ${revision} - 1.0.9 + 1.0.10 1.8 1.8 diff --git a/spring-boot-named/named-spring-boot-autoconfigure/pom.xml b/spring-boot-named/named-spring-boot-autoconfigure/pom.xml index 417717c7..616d9bc5 100644 --- a/spring-boot-named/named-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-named/named-spring-boot-autoconfigure/pom.xml @@ -14,6 +14,14 @@ named-spring-boot-autoconfigure + + org.javassist + javassist + + + org.reflections + reflections + org.springframework.boot spring-boot-starter-data-redis diff --git a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/NamedAutoConfiguration.java b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/NamedAutoConfiguration.java index 93dacb27..d8a79901 100644 --- a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/NamedAutoConfiguration.java +++ b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/NamedAutoConfiguration.java @@ -2,9 +2,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import in.hocg.boot.named.autoconfiguration.aspect.NamedAspect; -import in.hocg.boot.named.autoconfiguration.core.MemoryNamedCacheServiceImpl; import in.hocg.boot.named.autoconfiguration.core.NamedCacheService; import in.hocg.boot.named.autoconfiguration.core.RedisNamedCacheServiceImpl; +import in.hocg.boot.named.autoconfiguration.core.MemoryNamedCacheServiceImpl; import in.hocg.boot.named.autoconfiguration.core.convert.IPageNamedRowsConvert; import in.hocg.boot.named.autoconfiguration.core.convert.NamedRowsConvert; import in.hocg.boot.named.autoconfiguration.core.convert.OptionalNamedRowsConvert; diff --git a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/CachePool.java b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/CachePool.java index 09fc81fd..c1dd5058 100644 --- a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/CachePool.java +++ b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/CachePool.java @@ -1,12 +1,16 @@ package in.hocg.boot.named.autoconfiguration.core; -import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ReflectUtil; import com.google.common.collect.Maps; import in.hocg.boot.named.annotation.InjectNamed; import in.hocg.boot.named.annotation.NamedService; import in.hocg.boot.named.autoconfiguration.utils.NamedUtils; import in.hocg.boot.named.ifc.NamedHandler; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.reflections.Reflections; +import org.reflections.scanners.SubTypesScanner; +import org.reflections.scanners.TypeAnnotationsScanner; import org.springframework.aop.framework.AopProxyUtils; import org.springframework.context.ApplicationContext; import org.springframework.util.ClassUtils; @@ -22,6 +26,7 @@ * * @author hocgin */ +@Slf4j public class CachePool { public static Map, Object> NAMED_SERVICE_CLASS_MAPS = new WeakHashMap<>(); @@ -30,6 +35,7 @@ public class CachePool { * * @param context */ + @SneakyThrows public static void load(ApplicationContext context) { // 1.1 预热 NamedBean Map namedServiceMaps = context.getBeansOfType(NamedService.class); @@ -53,6 +59,8 @@ public static void load(ApplicationContext context) { ); // 2. 扫描字段 - ClassUtil.scanPackage().stream().filter(aClass -> aClass.isAnnotationPresent(InjectNamed.class)).forEach(NamedUtils::getAllField); + Reflections reflections = new Reflections(".*", new SubTypesScanner(), new TypeAnnotationsScanner()); + reflections.getTypesAnnotatedWith(InjectNamed.class).forEach(NamedUtils::getAllField); } + } diff --git a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/MemoryNamedCacheServiceImpl.java b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/MemoryNamedCacheServiceImpl.java index 33bf4c31..47ca1db0 100644 --- a/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/MemoryNamedCacheServiceImpl.java +++ b/spring-boot-named/named-spring-boot-autoconfigure/src/main/java/in/hocg/boot/named/autoconfiguration/core/MemoryNamedCacheServiceImpl.java @@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.InitializingBean; +import java.time.Duration; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -48,10 +49,11 @@ public void batchPut(Map caches) { @Override public void afterPropertiesSet() throws Exception { NamedProperties.CacheConfig cacheConfig = properties.getCache(); + Duration expired = cacheConfig.getExpired(); cachePool = CacheBuilder.newBuilder() .softValues() .maximumSize(10000L) - .expireAfterWrite(cacheConfig.getExpired()) + .expireAfterWrite(expired.getSeconds(), TimeUnit.SECONDS) .build(); } } diff --git a/spring-boot-starters-parent/pom.xml b/spring-boot-starters-parent/pom.xml index f2b77f4f..48a835db 100644 --- a/spring-boot-starters-parent/pom.xml +++ b/spring-boot-starters-parent/pom.xml @@ -46,6 +46,8 @@ v1-rev63-1.22.0 v1-rev10-1.22.0 1.20.0 + 0.9.10 + 3.25.0-GA @@ -544,6 +546,11 @@ jjwt ${jjwt.version} + + org.reflections + reflections + ${reflections.version} + com.github.binarywang weixin-java-cp @@ -599,6 +606,11 @@ google-collections ${google-collections.version} + + org.javassist + javassist + ${javassist.version} + diff --git a/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/advice/DefaultExceptionAdvice.java b/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/advice/DefaultExceptionAdvice.java index 9042b5f0..0da361fe 100644 --- a/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/advice/DefaultExceptionAdvice.java +++ b/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/advice/DefaultExceptionAdvice.java @@ -58,6 +58,22 @@ public ExceptionResult handleHttpMessageNotReadableException(HttpMessageNo return create(HttpStatus.BAD_REQUEST, message); } + @ExceptionHandler(value = {NullPointerException.class}) + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + public ExceptionResult handleNullPointerException(NullPointerException e) { + String message = "空指针异常"; + log.warn(message, e); + return create(HttpStatus.BAD_REQUEST, message); + } + + @ExceptionHandler(value = {UnsupportedOperationException.class}) + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + public ExceptionResult handleUnsupportedOperationException(UnsupportedOperationException e) { + String message = "操作不支持"; + log.warn(message, e); + return create(HttpStatus.BAD_REQUEST, message); + } + @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) public ExceptionResult handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { diff --git a/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/core/WarmUpLazyBeanRunner.java b/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/core/WarmUpLazyBeanRunner.java index 76a399ea..c0ccfc61 100644 --- a/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/core/WarmUpLazyBeanRunner.java +++ b/spring-boot-web/web-spring-boot-autoconfigure/src/main/java/in/hocg/boot/web/autoconfiguration/core/WarmUpLazyBeanRunner.java @@ -2,7 +2,6 @@ import in.hocg.boot.web.autoconfiguration.SpringContext; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeansException; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.context.ApplicationContext; @@ -24,7 +23,7 @@ public void run(ApplicationArguments args) throws Exception { log.debug("Warm Up Bean Task Start [{}]", WarmUpLazyBeanRunner.class); for (String beanDefinitionName : context.getBeanDefinitionNames()) { try { - context.getBean(beanDefinitionName); + context.getType(beanDefinitionName, true); } catch (Exception e) { log.warn("Warm Up Bean=[{}] Error: {}", beanDefinitionName, e); } finally {