Refine search
private static List<HandlerMapping> initFallback(ApplicationContext applicationContext) { Properties props; String path = "DispatcherServlet.properties"; try { Resource resource = new ClassPathResource(path, DispatcherServlet.class); props = PropertiesLoaderUtils.loadProperties(resource); } catch (IOException ex) { throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); } String value = props.getProperty(HandlerMapping.class.getName()); String[] names = StringUtils.commaDelimitedListToStringArray(value); List<HandlerMapping> result = new ArrayList<>(names.length); for (String name : names) { try { Class<?> clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader()); Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz); result.add((HandlerMapping) mapping); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]"); } } return result; }
private static String resolveJedisVersion() { String version = Jedis.class.getPackage().getImplementationVersion(); if (!StringUtils.hasText(version)) { try { Properties props = PropertiesLoaderUtils.loadAllProperties("META-INF/maven/redis.clients/jedis/pom.properties"); if (props.containsKey("version")) { version = props.getProperty("version"); } } catch (IOException e) { // ignore this one } } return version; }
/** * Load properties from the given resource (in ISO-8859-1 encoding). * @param resource the resource to load from * @return the populated Properties instance * @throws IOException if loading failed * @see #fillProperties(java.util.Properties, Resource) */ public static Properties loadProperties(Resource resource) throws IOException { Properties props = new Properties(); fillProperties(props, resource); return props; }
Properties mergedProps = new Properties(); if (this.resourceLoader != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, ResourceLoaderClassLoadHelper.class.getName()); mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, LocalTaskExecutorThreadPool.class.getName()); logger.debug("Loading Quartz config from [" + this.configLocation + "]"); PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
Properties props = new Properties(); logger.debug("Loading FreeMarker configuration from " + this.configLocation); PropertiesLoaderUtils.fillProperties(props, this.configLocation); props.putAll(this.freemarkerSettings); if (!props.isEmpty()) { config.setSettings(props);
@Override public void afterPropertiesSet() { try { Properties gitProperties = PropertiesLoaderUtils.loadAllProperties("git.properties"); commitId = gitProperties.getProperty("git.commit.id.abbrev", "UNKNOWN"); String currentTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()); timestamp = gitProperties.getProperty("git.commit.time", currentTime); } catch (IOException e) { logger.debug("Exception loading git.properties", e); } try { Properties buildProperties = PropertiesLoaderUtils.loadAllProperties("build.properties"); version = buildProperties.getProperty("build.version"); } catch (IOException e) { logger.debug("Exception loading build.properties", e); } Assert.hasText(uaaUrl); Assert.hasText(version); Assert.hasText(commitId); Assert.hasText(timestamp); }
private Properties loadProperties(Properties props, String url, String path) { log.info("Searching for properties in: " + url); Properties added = new Properties(); try { Resource resource = resources.getResource(url) .createRelative("META-INF/" + path); if (resource.exists()) { log.info("Loading properties from: " + resource); PropertiesLoaderUtils.fillProperties(added, resource); } resource = resources.getResource(url).createRelative("/" + path); if (resource.exists()) { log.info("Loading properties from: " + resource); PropertiesLoaderUtils.fillProperties(added, resource); } } catch (Exception e) { throw new IllegalStateException("Cannot load properties", e); } if (!added.isEmpty()) { merge(props, added); } return props; }
/** * 获取配置文件 * * @return 配置Props */ private static Properties getProperties() { // 读取配置文件 Resource resource = new ClassPathResource("/config/application.properties"); Properties props = new Properties(); try { props = PropertiesLoaderUtils.loadProperties(resource); } catch (IOException e) { e.printStackTrace(); } return props; }
public Properties getVersionProperties() { try { return PropertiesLoaderUtils.loadAllProperties("/META-INF/version.properties"); } catch (IOException e) { LOG.error("Unable to load version information", e); return new Properties(); } } }
/** * 配置数据库 */ private void configDatabase(HttpServletRequest request, Map<String, Object> map) { try { Properties dbconfig = PropertiesLoaderUtils.loadAllProperties(CmsDataSource.DATABASE_CONFIG_TEMPLATE); String host = request.getParameter("host"); String port = request.getParameter("port"); String database = request.getParameter("database"); cmsUpgrader.setDataBaseUrl(dbconfig, host, port, database); dbconfig.setProperty("jdbc.username", request.getParameter("username")); dbconfig.setProperty("jdbc.encryptPassword", VerificationUtils .base64Encode(VerificationUtils.encrypt(request.getParameter("password"), CommonConstants.ENCRYPT_KEY))); String databaseConfiFile = CommonConstants.CMS_FILEPATH + CmsDataSource.DATABASE_CONFIG_FILENAME; File file = new File(databaseConfiFile); try (FileOutputStream outputStream = new FileOutputStream(file);) { dbconfig.store(outputStream, null); } try (Connection connection = DatabaseUtils.getConnection(databaseConfiFile)) { } map.put("message", "success"); } catch (Exception e) { map.put("error", e.getMessage()); } }
@Test public void validateWithCustomBaseDir() throws Exception { File file = new File(this.folder.getRoot(), "metadata-store.properties"); PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore(); metadataStore.setBaseDirectory(folder.getRoot().getAbsolutePath()); metadataStore.afterPropertiesSet(); metadataStore.put("foo", "bar"); metadataStore.close(); assertTrue(file.exists()); Properties persistentProperties = PropertiesLoaderUtils.loadProperties(new FileSystemResource(file)); assertNotNull(persistentProperties); assertEquals(1, persistentProperties.size()); assertEquals("bar", persistentProperties.get("foo")); }
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) { MultiValueMap<String, String> result = cache.get(classLoader); if (result != null) { return result; } try { Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry<?, ?> entry : properties.entrySet()) { String factoryClassName = ((String) entry.getKey()).trim(); for (String factoryName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) { result.add(factoryClassName, factoryName.trim()); } } } cache.put(classLoader, result); return result; } catch (IOException ex) { throw new IllegalArgumentException("Unable to load factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex); } }
handlerNames = PropertiesLoaderUtils.loadAllProperties(location, loader); } catch (IOException e) { throw new WebxException("Could not load " + location, e); for (Map.Entry<?, ?> entry : handlerNames.entrySet()) { String name = normalizeRelativePath((String) entry.getKey(), true); // 规格化:xxx/yyy/zzz String handlerClass = trimToNull((String) entry.getValue());
PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader); if (logger.isTraceEnabled()) { logger.trace("Loaded schema mappings: " + mappings); schemaMappings = new ConcurrentHashMap<>(mappings.size()); CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings); this.schemaMappings = schemaMappings;
public void init() throws IOException { // Retrieve role list Properties rolesProps = PropertiesLoaderUtils.loadProperties(rolesResource); Object[] roles = rolesProps.keySet().toArray(new Object[0]); // Register roles in database for (Object enumRole : roles) { logger.debug("Create role : " + (String) enumRole); createRole((String) enumRole); } }
@Override public org.springframework.core.env.PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { Properties props = PropertiesLoaderUtils.loadProperties(resource); return new org.springframework.core.env.PropertySource<Properties>("my" + name, props) { @Override public Object getProperty(String name) { String value = props.getProperty(name); return (value != null ? value.toUpperCase() : null); } }; } }
/** * Load all properties from the specified class path resource * (in ISO-8859-1 encoding), using the default class loader. * <p>Merges properties if more than one resource of the same name * found in the class path. * @param resourceName the name of the class path resource * @return the populated Properties instance * @throws IOException if loading failed */ public static Properties loadAllProperties(String resourceName) throws IOException { return loadAllProperties(resourceName, null); }
/** * Fill the given properties from the given EncodedResource, * potentially defining a specific encoding for the properties file. * @param props the Properties instance to load into * @param resource the resource to load from * @throws IOException in case of I/O errors */ public static void fillProperties(Properties props, EncodedResource resource) throws IOException { fillProperties(props, resource, new DefaultPropertiesPersister()); }
Properties mergedProps = new Properties(); if (this.resourceLoader != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, ResourceLoaderClassLoadHelper.class.getName()); mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, LocalTaskExecutorThreadPool.class.getName()); logger.debug("Loading Quartz config from [" + this.configLocation + "]"); PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
Properties props = new Properties(); logger.debug("Loading FreeMarker configuration from " + this.configLocation); PropertiesLoaderUtils.fillProperties(props, this.configLocation); props.putAll(this.freemarkerSettings); if (!props.isEmpty()) { config.setSettings(props);