use of org.springframework.core.io.support.ResourcePatternResolver in project new-cloud by xie-summer.
the class MybatisConfigurer method sqlSessionFactoryBean.
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
// 分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
bean.setPlugins(new Interceptor[] { pageHelper });
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
bean.setMapperLocations(resolver.getResources("classpath:mapper/**.xml"));
return bean.getObject();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project spring-framework by spring-projects.
the class AbstractBeanDefinitionReader method loadBeanDefinitions.
/**
* Load bean definitions from the specified resource location.
* <p>The location can also be a location pattern, provided that the
* ResourceLoader of this bean definition reader is a ResourcePatternResolver.
* @param location the resource location, to be loaded with the ResourceLoader
* (or ResourcePatternResolver) of this bean definition reader
* @param actualResources a Set to be filled with the actual Resource objects
* that have been resolved during the loading process. May be {@code null}
* to indicate that the caller is not interested in those Resource objects.
* @return the number of bean definitions found
* @throws BeanDefinitionStoreException in case of loading or parsing errors
* @see #getResourceLoader()
* @see #loadBeanDefinitions(org.springframework.core.io.Resource)
* @see #loadBeanDefinitions(org.springframework.core.io.Resource[])
*/
public int loadBeanDefinitions(String location, @Nullable Set<Resource> actualResources) throws BeanDefinitionStoreException {
ResourceLoader resourceLoader = getResourceLoader();
if (resourceLoader == null) {
throw new BeanDefinitionStoreException("Cannot load bean definitions from location [" + location + "]: no ResourceLoader available");
}
if (resourceLoader instanceof ResourcePatternResolver) {
// Resource pattern matching available.
try {
Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location);
int count = loadBeanDefinitions(resources);
if (actualResources != null) {
Collections.addAll(actualResources, resources);
}
if (logger.isTraceEnabled()) {
logger.trace("Loaded " + count + " bean definitions from location pattern [" + location + "]");
}
return count;
} catch (IOException ex) {
throw new BeanDefinitionStoreException("Could not resolve bean definition resource pattern [" + location + "]", ex);
}
} else {
// Can only load single resources by absolute URL.
Resource resource = resourceLoader.getResource(location);
int count = loadBeanDefinitions(resource);
if (actualResources != null) {
actualResources.add(resource);
}
if (logger.isTraceEnabled()) {
logger.trace("Loaded " + count + " bean definitions from location [" + location + "]");
}
return count;
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project spring-framework by spring-projects.
the class ResourceEditorRegistrar method registerCustomEditors.
/**
* Populate the given {@code registry} with the following resource editors:
* ResourceEditor, InputStreamEditor, InputSourceEditor, FileEditor, URLEditor,
* URIEditor, ClassEditor, ClassArrayEditor.
* <p>If this registrar has been configured with a {@link ResourcePatternResolver},
* a ResourceArrayPropertyEditor will be registered as well.
* @see org.springframework.core.io.ResourceEditor
* @see org.springframework.beans.propertyeditors.InputStreamEditor
* @see org.springframework.beans.propertyeditors.InputSourceEditor
* @see org.springframework.beans.propertyeditors.FileEditor
* @see org.springframework.beans.propertyeditors.URLEditor
* @see org.springframework.beans.propertyeditors.URIEditor
* @see org.springframework.beans.propertyeditors.ClassEditor
* @see org.springframework.beans.propertyeditors.ClassArrayEditor
* @see org.springframework.core.io.support.ResourceArrayPropertyEditor
*/
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader, this.propertyResolver);
doRegisterEditor(registry, Resource.class, baseEditor);
doRegisterEditor(registry, ContextResource.class, baseEditor);
doRegisterEditor(registry, InputStream.class, new InputStreamEditor(baseEditor));
doRegisterEditor(registry, InputSource.class, new InputSourceEditor(baseEditor));
doRegisterEditor(registry, File.class, new FileEditor(baseEditor));
doRegisterEditor(registry, Path.class, new PathEditor(baseEditor));
doRegisterEditor(registry, Reader.class, new ReaderEditor(baseEditor));
doRegisterEditor(registry, URL.class, new URLEditor(baseEditor));
ClassLoader classLoader = this.resourceLoader.getClassLoader();
doRegisterEditor(registry, URI.class, new URIEditor(classLoader));
doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
doRegisterEditor(registry, Class[].class, new ClassArrayEditor(classLoader));
if (this.resourceLoader instanceof ResourcePatternResolver) {
doRegisterEditor(registry, Resource[].class, new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader, this.propertyResolver));
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyImportRulesFiles.
private void copyImportRulesFiles() throws IOException {
ByteArrayInputStream[] listSrcFiles = new ByteArrayInputStream[3];
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
String[] fileNames = { "rules.xsd", "rules_template.xml", "rules_template_with_notes.xml" };
Resource[] resources = null;
FileOutputStream out = null;
resources = resolver.getResources("classpath*:properties/rules_template*.xml");
File dest = new File(getField("filePath") + "rules");
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
}
}
for (Resource r : resources) {
File f = new File(dest, r.getFilename());
out = new FileOutputStream(f);
IOUtils.copy(r.getInputStream(), out);
out.close();
}
Resource[] r1 = resolver.getResources("classpath*:properties/" + fileNames[0]);
File f1 = new File(dest, r1[0].getFilename());
out = new FileOutputStream(f1);
IOUtils.copy(r1[0].getInputStream(), out);
out.close();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyODMMappingXMLtoResources.
private void copyODMMappingXMLtoResources(ResourceLoader resourceLoader) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
String[] fileNames = { "cd_odm_mapping.xml" };
Resource[] resources;
try {
resources = resolver.getResources("classpath*:properties/cd_odm_mapping.xml");
} catch (IOException ioe) {
OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to read source files");
oe.initCause(ioe);
oe.setStackTrace(ioe.getStackTrace());
logger.debug(ioe.getMessage());
throw oe;
}
File dest = null;
try {
dest = new File(getField("filePath"));
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
}
}
File f = new File(dest, resources[0].getFilename());
FileOutputStream out = new FileOutputStream(f);
IOUtils.copy(resources[0].getInputStream(), out);
out.close();
} catch (IOException ioe) {
OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to get web app base path");
oe.initCause(ioe);
oe.setStackTrace(ioe.getStackTrace());
throw oe;
}
}
Aggregations