Skip to content

Commit

Permalink
Merge pull request #64 from hocgin/1.0.10
Browse files Browse the repository at this point in the history
feat: 1.0.10
  • Loading branch information
hocgin authored Jul 21, 2021
2 parents 5221a62 + df70e7a commit 16b056b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<version>${revision}</version>

<properties>
<revision>1.0.9</revision>
<revision>1.0.10</revision>

<java.version>1.8</java.version>
<java.source.version>1.8</java.source.version>
Expand Down
8 changes: 8 additions & 0 deletions spring-boot-named/named-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<artifactId>named-spring-boot-autoconfigure</artifactId>

<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +26,7 @@
*
* @author hocgin
*/
@Slf4j
public class CachePool {
public static Map<Class<?>, Object> NAMED_SERVICE_CLASS_MAPS = new WeakHashMap<>();

Expand All @@ -30,6 +35,7 @@ public class CachePool {
*
* @param context
*/
@SneakyThrows
public static void load(ApplicationContext context) {
// 1.1 预热 NamedBean
Map<String, NamedService> namedServiceMaps = context.getBeansOfType(NamedService.class);
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,10 +49,11 @@ public void batchPut(Map<String, Object> 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();
}
}
12 changes: 12 additions & 0 deletions spring-boot-starters-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<google-api-services-youtubeAnalytics.version>v1-rev63-1.22.0</google-api-services-youtubeAnalytics.version>
<google-api-services-youtubereporting.version>v1-rev10-1.22.0</google-api-services-youtubereporting.version>
<google-http-client-jackson2.version>1.20.0</google-http-client-jackson2.version>
<reflections.version>0.9.10</reflections.version>
<javassist.version>3.25.0-GA</javassist.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -544,6 +546,11 @@
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-cp</artifactId>
Expand Down Expand Up @@ -599,6 +606,11 @@
<artifactId>google-collections</artifactId>
<version>${google-collections.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public ExceptionResult<Void> handleHttpMessageNotReadableException(HttpMessageNo
return create(HttpStatus.BAD_REQUEST, message);
}

@ExceptionHandler(value = {NullPointerException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ExceptionResult<Void> 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<Void> 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<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 16b056b

Please sign in to comment.