use of com.littlefisher.core.exception.BaseAppException in project littlefisher-system by littlefishercoder.
the class PackageUtil method scanTypePackage.
/**
* 扫描获取指定包路径所有类
*
* @param typePackage 扫描类包路径
* @return Set<Class>
*/
public static Set<Class> scanTypePackage(String typePackage) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
String pkg = ClassUtils.convertClassNameToResourcePath(typePackage) + ".class";
/*
* 将加载多个绝对匹配的所有Resource
* 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
*/
try {
Set<Class> set = Sets.newHashSet();
Resource[] resources = resolver.getResources(pkg);
if (ArrayUtils.isNotEmpty(resources)) {
MetadataReader metadataReader;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return set;
} catch (Exception e) {
throw new BaseAppException("CORE-000007", null, e);
}
}
use of com.littlefisher.core.exception.BaseAppException in project littlefisher-system by littlefishercoder.
the class MyBatisConfig method customize.
@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
String typeEnumsPackage = littleFisherProperties.getMybatis().getTypeEnumsPackage();
final Set<Class> classes = Sets.newHashSet();
if (StringUtil.isNotBlank(typeEnumsPackage)) {
String[] typeEnumsPackageArray = StringUtils.tokenizeToStringArray(typeEnumsPackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
Arrays.stream(typeEnumsPackageArray).forEach(typeEnumsPackageStr -> classes.addAll(PackageUtil.scanTypePackage(typeEnumsPackage)));
// 取得类型转换注册器
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
try {
for (Class cls : classes) {
if (cls.isEnum()) {
if (IEnum.class.isAssignableFrom(cls)) {
typeHandlerRegistry.register(cls.getName(), EnumTypeHandler.class.getName());
} else {
// 使用原生 EnumOrdinalTypeHandler
typeHandlerRegistry.register(cls.getName(), EnumOrdinalTypeHandler.class.getName());
}
}
}
} catch (ClassNotFoundException e) {
throw new BaseAppException("CORE-000007", null, e);
}
}
}
use of com.littlefisher.core.exception.BaseAppException in project littlefisher-system by littlefishercoder.
the class ExceptionHandler method publish.
public static void publish(String errorCode, String message, Throwable t, String param1, String param2, String param3, String param4, String param5) {
BaseAppException baseAppException;
if (t != null && t instanceof BaseAppException) {
baseAppException = (BaseAppException) t;
} else if (t != null && t instanceof InvocationTargetException) {
// 仅仅对此情况进行处理,不能进行深层检查!
Throwable cause = t.getCause();
if (cause instanceof BaseAppException) {
baseAppException = (BaseAppException) cause;
} else {
baseAppException = new BaseAppException(errorCode, message, t, param1, param2, param3, param4, param5);
}
} else {
baseAppException = new BaseAppException(errorCode, message, t, param1, param2, param3, param4, param5);
}
logErrorInfo(baseAppException);
throw baseAppException;
}
Aggregations