Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:com.iopr.DBResource.java

@Bean
public static PropertyPlaceholderConfigurer properties() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Resource[] resources = new ClassPathResource[] { new ClassPathResource("db.properties") };
    ppc.setLocations(resources);/*from  ww w. j  a v  a  2  s . c om*/
    ppc.setIgnoreUnresolvablePlaceholders(true);
    return ppc;
}

From source file:com.eventattend.portal.Factory.LoginFactory.java

public static LoginController loginUserInfo() throws Exception {
    ClassPathResource resource = new ClassPathResource("BusinessObjectFactory.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    return (LoginController) factory.getBean("checkUser");
}

From source file:ru.mystamps.web.config.ApplicationContext.java

@Bean
public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setLocations(new ClassPathResource("sql/category_dao_queries.properties"),
            new ClassPathResource("sql/country_dao_queries.properties"),
            new ClassPathResource("sql/collection_dao_queries.properties"),
            new ClassPathResource("sql/image_dao_queries.properties"),
            new ClassPathResource("sql/user_dao_queries.properties"),
            new ClassPathResource("sql/users_activation_dao_queries.properties"),
            new ClassPathResource("sql/series_dao_queries.properties"),
            new ClassPathResource("sql/series_sales_dao_queries.properties"),
            new ClassPathResource("sql/suspicious_activity_dao_queries.properties"),
            new ClassPathResource("sql/transaction_participants_dao_queries.properties"));
    return configurer;
}

From source file:com.wavemaker.commons.util.SpringUtils.java

public static Object getBean(String cfg, String beanName) {
    return getBean(new ClassPathResource(cfg), beanName);
}

From source file:com.cocktail.initializer.ItemReader.java

/**
 * Read items.//from  w w  w .  ja  va2s.c o  m
 *
 * @param <I>
 *            the generic type
 * @param path
 *            the path
 * @param itemMapper
 *            the item mapper
 * @return the list
 * @throws Exception
 *             the exception
 */
public static <I> List<I> readItems(String path, FieldSetMapper<I> itemMapper) throws Exception {

    ClassPathResource resource = new ClassPathResource(path);
    Scanner scanner = new Scanner(resource.getInputStream());
    String line = scanner.nextLine();
    scanner.close();

    FlatFileItemReader<I> itemReader = new FlatFileItemReader<I>();
    itemReader.setResource(resource);

    // DelimitedLineTokenizer defaults to | as its delimiter
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer("|");
    tokenizer.setNames(line.split("\\|"));
    tokenizer.setStrict(false);

    DefaultLineMapper<I> lineMapper = new DefaultLineMapper<I>();
    lineMapper.setLineTokenizer(tokenizer);
    lineMapper.setFieldSetMapper(itemMapper);
    itemReader.setLineMapper(lineMapper);
    itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy());
    itemReader.setLinesToSkip(1);
    itemReader.open(new ExecutionContext());

    List<I> items = new ArrayList<>();
    I item = null;

    do {

        item = itemReader.read();

        if (item != null) {
            items.add(item);
        }

    } while (item != null);

    return items;
}

From source file:biz.c24.io.spring.integration.test.TestUtils.java

public static byte[] loadCsvBytes() throws Exception {

    ClassPathResource resource = new ClassPathResource("valid-1.txt");
    byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream());

    return valid1;
}

From source file:com.charandeepmatta.database.di.Schema.java

private static void updateSqlFromFile(final JdbcTemplate jdbc, final String fileName) throws IOException {
    ClassPathResource base = new ClassPathResource(fileName);
    updateSqlTo(jdbc, base.getInputStream());
}

From source file:com.framework.service.logconfig.LogConfigServiceImpl.java

@SuppressWarnings("unchecked")
@Cacheable("logConfig")
public List<LogConfig> getAll() {
    try {/*from   ww  w  . j  a v  a 2 s .  c  om*/
        File shopxxXmlFile = new ClassPathResource("/framework.xml").getFile();
        Document document = new SAXReader().read(shopxxXmlFile);
        List<org.dom4j.Element> elements = document.selectNodes("/framework/logConfig");
        List<LogConfig> logConfigs = new ArrayList<LogConfig>();
        for (org.dom4j.Element element : elements) {
            String logType = element.attributeValue("logType");
            int logLevel = Integer.parseInt((String) element.attributeValue("logLevel"));
            String operatObject = element.attributeValue("operatObject");
            String urlPattern = element.attributeValue("urlPattern");
            LogConfig logConfig = new LogConfig();
            logConfig.setLogType(logType);
            logConfig.setLogLevel(logLevel);
            logConfig.setUrlPattern(urlPattern);
            logConfig.setOperatObject(operatObject);
            logConfigs.add(logConfig);
        }
        return logConfigs;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:hu.petabyte.redflags.engine.RedflagsEngineApp.java

private static void exportConfig(String fn) {
    try {/*from w  w w  . j a  v a2 s.  com*/
        StreamUtils.copyToString(new ClassPathResource("application.yml").getInputStream(),
                Charset.forName("UTF-8"));
        System.out.println("Internal application.yml copied out to " + fn);
    } catch (IOException e) {
        System.out.println("Operation failed: " + e.getMessage());
    }
}

From source file:com.formkiq.core.util.Resources.java

/**
 * Gets a file from classpath as bytes./*from  w  w  w .java2s .co  m*/
 * @param file {@link String}
 * @return {@link String}
 * @throws IOException IOException
 */
public static InputStream getResourceAsInputStream(final String file) throws IOException {

    InputStream is = null;
    Resource resource = new ClassPathResource(file);

    try {
        is = resource.getInputStream();
    } catch (FileNotFoundException e) {

        // check for file in tomcat conf directory
        String catalinabase = System.getProperty("catalina.base");

        if (StringUtils.hasText(catalinabase)) {
            File configDir = new File(catalinabase, "conf");
            File configFile = new File(configDir, file);

            if (configFile.exists()) {
                is = new FileInputStream(configFile);
            }
        }
    }

    return is;
}