2024-09-11 08:38
@JFinal 加上addHotSwapClassPrefix没有效果,把undertow.devMode=false就可以了。麻烦指导下怎么解决这个问题。
2024-09-02 09:22
@JFinal spring框架里有PathMatchingResourcePatternResolver可用用来扫描指定包路径下的class,可以根据ant风格模糊匹配某项包下的class文件,现在不想依赖spring框架,jfinal下有类似的类扫描方法吗?代码如下:
public static Class[] scanBasePackage(ScannedClassFilter filter, String... basePackages) {
Set> classSet = new LinkedHashSet<>();
Set resources = getResources(basePackages);
for (Resource resource : resources) {
Class clazz = resolveClassFromResource(resource);
if (filter == null || filter.filter(clazz)) {
classSet.add(clazz);
}
}
return classSet.toArray(new Class[classSet.size()]);
}
private static Set getResources(String[] basePackages) {
Set set = new LinkedHashSet<>();
Resource[] resources;
try {
for (String basePackage : basePackages) {
if (StringUtils.isBlank(basePackage)) {
basePackage = "";
} else {
basePackage = basePackage.replace(".", "/");
if (!basePackage.endsWith("/")) {
basePackage += "/";
}
}
basePackage = "classpath*:" + basePackage + "**/*.class";
resources = resourceLoader.getResources(basePackage);
set.addAll(Arrays.asList(resources));
}
} catch (IOException e) {
throw new RuntimeException("scan basePackage(s) error.", e);
}
return set;
}