Ant path资源加载

SPRING提供了类似ANT的路径方式来加载资源(包含从JAR中加载资源),如:classpath*:/config/tx/**/*.service.xml

    /**
     * <pre>
     * Ant path方式的文件查找
     * 支持
     * classpath*:/
     * classpath:/
     * 等的通配符搜索
     * </pre>
     * @param pattern
     * @return 所有符合条件的文件流
     */
    public static InputStream[] loadStreams(String pattern) {
        PathMatchingResourcePatternResolver rs = new PathMatchingResourcePatternResolver();
        try {
            Resource[] resources = rs.getResources(pattern);
            if (resources != null && resources.length > 0) {
                InputStream[] streams = new InputStream[resources.length];
                for (int i = 0; i < resources.length; i++) {
                    streams[i] = resources[i].getInputStream();
                }
                return streams;
            } else {
                return new InputStream[] {};
            }
        } catch (IOException e) {
            return new InputStream[] {};
        }
    }


你可能感兴趣的:(spring,xml,ant)