/** * Return array or resource that match given pattern * * @param pattern * Pattern to check against * @return Array of Resource objects * @throws IOException * On I/O exception * * @see org.springframework.core.io.Resource */ public Resource[] getResources(String pattern) throws IOException { return applicationContext.getResources(contextPath + pattern); }
/** * Create a parent ClassLoader for Groovy to use as parent ClassLoader * when loading and compiling templates. */ protected ClassLoader createTemplateClassLoader() throws IOException { String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath()); List<URL> urls = new ArrayList<>(); for (String path : paths) { Resource[] resources = getApplicationContext().getResources(path); if (resources.length > 0) { for (Resource resource : resources) { if (resource.exists()) { urls.add(resource.getURL()); } } } } ClassLoader classLoader = getApplicationContext().getClassLoader(); Assert.state(classLoader != null, "No ClassLoader"); return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[0]), classLoader) : classLoader); }
/** * Create a parent ClassLoader for Groovy to use as parent ClassLoader * when loading and compiling templates. */ protected ClassLoader createTemplateClassLoader() throws IOException { String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath()); List<URL> urls = new ArrayList<>(); for (String path : paths) { Resource[] resources = getApplicationContext().getResources(path); if (resources.length > 0) { for (Resource resource : resources) { if (resource.exists()) { urls.add(resource.getURL()); } } } } ClassLoader classLoader = getApplicationContext().getClassLoader(); Assert.state(classLoader != null, "No ClassLoader"); return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[0]), classLoader) : classLoader); }
@Bean(name = "sqlSessionFactory") public SqlSessionFactoryBean sqlSessionFactory(ApplicationContext applicationContext) throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); // sessionFactory.setPlugins(new Interceptor[]{new PageInterceptor()}); sessionFactory.setMapperLocations(applicationContext.getResources("classpath*:mapper/*.xml")); return sessionFactory; }
ldifs = ctxt.getResources(ldifResources);
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }
@Bean(name = "sqlSessionFactory") public SqlSessionFactoryBean sqlSessionFactory( ApplicationContext applicationContext) throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); configuration.setMapUnderscoreToCamelCase(true); configuration.setJdbcTypeForNull(JdbcType.NULL); sessionFactory.setMapperLocations(applicationContext.getResources("classpath:mapper/*.xml")); return sessionFactory; }
@Bean(name = "sqlSessionFactory") public SqlSessionFactoryBean sqlSessionFactory( ApplicationContext applicationContext) throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); configuration.setMapUnderscoreToCamelCase(true); configuration.setJdbcTypeForNull(JdbcType.NULL); configuration.setLogImpl(org.apache.ibatis.logging.log4j.Log4jImpl.class);//use log4j log sessionFactory.setConfiguration(configuration); sessionFactory.setMapperLocations(applicationContext.getResources("classpath:com/yy/example/mapper/*.xml")); // // Properties prop = new Properties(); // prop.setProperty("supportMethodsArguments","true"); // prop.setProperty("rowBoundsWithCount", "true"); // prop.setProperty("params","pageNum=pageNum;pageSize=pageSize;"); // PageInterceptor pi = new PageInterceptor(); // pi.setProperties(prop); // sessionFactory.setPlugins(new Interceptor[]{pi}); return sessionFactory; }
for (String location : locations) { try { Resource[] resources = context.getResources(location); if (resources != null) { for (Resource resource : resources) {
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext); DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory; String resolvedPath = resolvePackageToScan(); logger.debug("Scanning '{}' for JSON-RPC service interfaces.", resolvedPath); try { for (Resource resource : applicationContext.getResources(resolvedPath)) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); ClassMetadata classMetadata = metadataReader.getClassMetadata(); AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); String jsonRpcPathAnnotation = JsonRpcService.class.getName(); if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) { String className = classMetadata.getClassName(); String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation).get("value"); logger.debug("Found JSON-RPC service to proxy [{}] on path '{}'.", className, path); registerJsonProxyBean(defaultListableBeanFactory, className, path); } } } } catch (IOException e) { throw new IllegalStateException(format("Cannot scan package '%s' for classes.", resolvedPath), e); } }
/** * @param arg0 * @return * @throws IOException * @see org.springframework.core.io.support.ResourcePatternResolver#getResources(java.lang.String) */ public Resource[] getResources(String arg0) throws IOException { return target.getResources(arg0); }
/** * Delegates to internal ApplicationContext supplied by constructor */ public final Resource[] getResources(String arg0) throws IOException { return context.getResources(arg0); }
@Autowired private ApplicationContext applicationContext; private Resource[] resources ; public loadResources() { try { resources = applicationContext.getResources("file:C:/XYZ/*_vru_*"); } catch (IOException ex) { ex.printStackTrace(); } }
@Override public URL[] getObject() throws Exception { List<URL> resources = new ArrayList<URL>(); for (String location : locations) { for (Resource resource : applicationContext.getResources(location)) { resources.add(resource.getURL()); } } return resources.toArray(new URL[resources.size()]); }
@Override public List<String> schemaStrings() throws IOException { Resource[] resources = applicationContext.getResources("classpath*:" + schemaLocationPattern); if (resources.length <= 0) { throw new IllegalStateException( "No graphql schema files found on classpath with location pattern '" + schemaLocationPattern + "'. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context."); } return Arrays.stream(resources) .map(this::readSchema) .collect(Collectors.toList()); }
@Override public Resource[] getResources( String s ) throws IOException { return applicationContext.getResources( s ); }
public void findBundles() throws IOException { Resource[] resources = applicationContext.getResources("classpath*:"+BUNDLE_CONF_FILE); logger.debug("Found {} boundle definition", resources.length); for (Resource resource : resources) { parseBundleXml(resource.getInputStream()); } }
private static boolean isUsingCloudServices(ApplicationContext applicationContext) { try { return Arrays.stream(applicationContext.getResources("classpath*:/META-INF/cloud/cloud-services")) .flatMap(ApplicationContextCloudServicesHolder::getCloudServiceClasses) .filter(ApplicationContextCloudServicesHolder::isClassPresent) .anyMatch(klass -> hasBeansOfType(applicationContext, klass)); } catch (IOException e) { LOGGER.warning("Unable to read cloud service classes"); return false; } }
private void findResources(ApplicationContext applicationContext, String pattern) { try { for (Resource resource : applicationContext.getResources(pattern)) { model.add(resource); } } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
private void register(String[] paths) throws DuplicateJobException, IOException { maybeCreateJobLoader(); for (int i = 0; i < paths.length; i++) { Resource[] resources = parentContext.getResources(paths[i]); for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; logger.info("Registering Job definitions from " + Arrays.toString(resources)); GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); jobLoader.load(factory); } } }