fix[resource]: use classpath* to solve the problem that some resources cannot be loaded

This commit is contained in:
godotg
2023-04-08 16:54:02 +08:00
parent 2be5f3f267
commit ef2847aa64
2 changed files with 4 additions and 4 deletions
@@ -28,8 +28,8 @@ import com.zfoo.protocol.xml.XmlProtocols;
import io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import java.io.IOException;
import java.util.function.Predicate;
@@ -115,7 +115,7 @@ public class PacketService implements IPacketService {
GenerateProtocolFile.generateProtocolFilter = netGenerateProtocolFilter;
// 解析protocol.xml文件,并将协议生成ProtocolRegistration
var resource = applicationContext.getResource(ResourceUtils.CLASSPATH_URL_PREFIX + protocolLocation);
var resource = applicationContext.getResource(ResourcePatternResolver.CLASSPATH_URL_PREFIX + protocolLocation);
try {
var xmlProtocols = DomUtils.inputStream2Object(resource.getInputStream(), XmlProtocols.class);
ProtocolManager.initProtocol(xmlProtocols, generateOperation);
@@ -32,10 +32,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -230,7 +230,7 @@ public class StorageManager implements IStorageManager {
try {
var result = new HashSet<String>();
for (var scanPackage : scanPackages) {
var packageSearchPath = ResourceUtils.CLASSPATH_URL_PREFIX + scanPackage.replace(StringUtils.PERIOD, StringUtils.SLASH) + StringUtils.SLASH + SUFFIX_PATTERN;
var packageSearchPath = ResourcePatternResolver.CLASSPATH_URL_PREFIX + scanPackage.replace(StringUtils.PERIOD, StringUtils.SLASH) + StringUtils.SLASH + SUFFIX_PATTERN;
var resources = resourcePatternResolver.getResources(packageSearchPath);
var resourceName = com.zfoo.storage.model.anno.Resource.class.getName();
for (var resource : resources) {