Search in sources :

Example 1 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot-admin by codecentric.

the class ResourcePatternResolvingResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    ResourceResolver resolver = new ResourcePatternResolvingResourceResolver(new PathMatchingResourcePatternResolver(), "classpath:/t*Resource.txt");
    resolver.resolveResource(null, null, null, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(1));
            assertThat(locations.get(0).getFilename(), is("testResource.txt"));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceResolver(org.springframework.web.servlet.resource.ResourceResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Example 2 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot by spring-projects.

the class ResourceMatcher method findInFolder.

private List<MatchedResource> findInFolder(File folder) throws IOException {
    List<MatchedResource> matchedResources = new ArrayList<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new FolderResourceLoader(folder));
    for (String include : this.includes) {
        for (Resource candidate : resolver.getResources(include)) {
            File file = candidate.getFile();
            if (file.isFile()) {
                MatchedResource matchedResource = new MatchedResource(folder, file);
                if (!isExcluded(matchedResource)) {
                    matchedResources.add(matchedResource);
                }
            }
        }
    }
    return matchedResources;
}
Also used : ArrayList(java.util.ArrayList) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) File(java.io.File)

Example 3 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver 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);
    }
}
Also used : BaseAppException(com.littlefisher.core.exception.BaseAppException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) BaseAppException(com.littlefisher.core.exception.BaseAppException)

Example 4 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project midpoint by Evolveum.

the class ActivitiEngine method autoDeploy.

private void autoDeploy() {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    String[] autoDeploymentFrom = wfConfiguration.getAutoDeploymentFrom();
    for (String adf : autoDeploymentFrom) {
        Resource[] resources;
        try {
            resources = resolver.getResources(adf);
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resources to be automatically deployed from " + adf, e);
            continue;
        }
        LOGGER.info("Auto deployment from " + adf + " yields " + resources.length + " resource(s)");
        for (Resource resource : resources) {
            try {
                autoDeployResource(resource);
            } catch (IOException | XPathExpressionException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't deploy the resource " + resource, e);
            }
        }
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 5 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project leopard by tanhaichao.

the class ConfigClasspathImpl method find.

@Override
public InputStream find() throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources;
    try {
        resources = resolver.getResources("classpath*:/dev/dns.properties");
    } catch (IOException e) {
        e.printStackTrace();
        throw new FileNotFoundException("classpath*:/dev/dns.properties");
    }
    for (Resource resource : resources) {
        try {
            InputStream is = resource.getInputStream();
            return is;
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    throw new FileNotFoundException("classpath*:/dev/dns.properties");
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6