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.milkdairy.admin.MilkDairyManagement.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Resource resource = new ClassPathResource("applicationContext.xml");
            BeanFactory factory = new XmlBeanFactory(resource);

            JPanel milkDairyManagementJPanel = (MilkDairyManagementJPanel) factory
                    .getBean("milkDairyManagementJPanel");

            UIManager.put("swing.boldmetal", Boolean.FALSE);

            new LoginJFrame(milkDairyManagementJPanel, (LoggingService) factory.getBean("loggingService"))
                    .setVisible(true);/*from w w  w  .  j a v a 2  s . co  m*/

        }

    });
}

From source file:com.enitalk.controllers.youtube.CalendarTest.java

public static void main(String[] args) throws IOException {

    InputStream is = new ClassPathResource("events.json").getInputStream();
    ObjectMapper jackson = new ObjectMapper();
    JsonNode tree = jackson.readTree(is);
    IOUtils.closeQuietly(is);/*www .j  a v  a  2s .  c o m*/

    DateTimeFormatter fmtDateTime = ISODateTimeFormat.dateTimeNoMillis();
    DateTimeFormatter fmt = ISODateTimeFormat.date();

    TreeMultimap<DateTime, DateTime> set = CalendarTest.getPeriodSet(10, 18);

    Iterator<JsonNode> nodes = tree.elements();
    while (nodes.hasNext()) {
        JsonNode ev = nodes.next();
        boolean isFullDay = ev.path("start").has("date");

        DateTime stDate = isFullDay ? fmt.parseDateTime(ev.path("start").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("start").path("dateTime").asText());

        DateTime enDate = isFullDay ? fmt.parseDateTime(ev.path("end").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("end").path("dateTime").asText());

        System.out.println("St " + stDate + " en " + enDate);

        int days = Days.daysBetween(stDate, enDate).getDays();
        System.out.println("Days between " + days);
        if (isFullDay) {
            switch (days) {
            case 1:
                set.removeAll(stDate);
                break;
            default:
                while (days-- > 0) {
                    set.removeAll(stDate.plusDays(days));
                }
            }
        } else {
            DateTime copySt = stDate.minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);
            DateTime copyEn = enDate.plusHours(1).minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);

            //                System.out.println("Dates truncated " + copySt + " " + copyEn);
            //                System.out.println("Ll set " + set);

            //                System.out.println("Getting set for key " + stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> ss = set.get(stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> subset = ss.subSet(copySt, copyEn);
            subset.clear();
            set.remove(enDate.millisOfDay().setCopy(0), copyEn);
        }

    }

}

From source file:com.apress.prospringintegration.web.MultipartHttpClient.java

public static void main(String[] args) {
    RestTemplate template = new RestTemplate();
    String uri = "http://localhost:8080/http-adapter-1.0.0/inboundMultipartAdapter.html";
    Resource picture = new ClassPathResource("com/apress/prospringintegration/web/test.png");
    MultiValueMap map = new LinkedMultiValueMap();
    map.add("name", "John Smith");
    map.add("picture", picture);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("multipart", "form-data"));
    HttpEntity request = new HttpEntity(map, headers);
    ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, null);
    System.out.println("Status: " + httpResponse.getStatusCode().name());
}

From source file:com.mulodo.hadoop.wordcount.Application.java

public static void main(String[] args) throws IOException {

    Resource resource = new ClassPathResource("application.properties");
    Properties props = PropertiesLoaderUtils.loadProperties(resource);

    System.out.println(props.getProperty("spring.hadoop.fsUri"));
    System.out.println(props.getProperty("spring.hadoop.resourceManagerHost"));
    System.out.println(props.getProperty("spring.hadoop.jobHistoryAddress"));

    SpringApplication.run(Application.class, args);
}

From source file:com.cazcade.billabong.image.impl.ImageMain.java

public static void main(String[] args) throws URISyntaxException {
    BeanFactory factory = new XmlBeanFactory(new ClassPathResource("/spring/image-service.xml"));
    ImageService service = (ImageService) factory.getBean("imageService");
    //        sendRequest(service, "http://c0021791.cdn1.cloudfiles.rackspacecloud.com/12bd4a28-8e01-4662-8faf-ca5dee21449b.png");
    //        sendImageRequest(service, "http://c0021791.cdn1.cloudfiles.rackspacecloud.com/12bd4a28-8e01-4662-8faf-ca5dee21449b.png");
    sendRequest(service, "http://www.msn.com");
    sendRequest(service, "http://www.google.com");
    sendRequest(service, "http://www.amazon.com");
    sendRequest(service, "http://www.theregister.co.uk");
    sendRequest(service, "http://www.slashdot.org");
    sendRequest(service, "http://news.bbc.co.uk");
}

From source file:org.spring.resource.FileSourceExample.java

public static void main(String[] args) {
    try {//from w w w  .ja  v a2  s  . c o  m
        String filePath = "E:\\JEELearning\\ideaworlplace\\springdream\\springdream.ioc\\src\\main\\resources\\FileSource.txt";
        // ?
        Resource res1 = new FileSystemResource(filePath);
        // ?
        Resource res2 = new ClassPathResource("FileSource.txt");

        System.out.println("?:" + res1.getFilename());
        System.out.println("?:" + res2.getFilename());

        InputStream in1 = res1.getInputStream();
        InputStream in2 = res2.getInputStream();
        //            System.out.println("?:" + read(in1));
        //            System.out.println("?:" + read(in2));
        System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in1)));
        System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in2)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.springdeveloper.hadoop.hive.HiveApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hive-context.xml",
            HiveApp.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();//from   w  ww .j  a  va 2 s .  c om

    HiveTemplate template = context.getBean(HiveTemplate.class);

    HiveScript script = new HiveScript(new ClassPathResource("tweet-influencers.hql"));

    template.executeScript(script);

    context.close();
}

From source file:org.apius.server.JseComponentBootstrap.java

/**
 * Takes two string parameters://from w  ww.jav  a 2  s.  co m
 * 1) Classpath to the bean factory.
 * 2) Name (ref) of the Restlet Component as indicated in the bean factory XML file.
 * 
 * @param path
 * @param name
 * @return void
 */
public static void main(String[] args) throws Exception {

    String resourceClassPath = args[0];
    String componentBean = args[1];

    ClassPathResource resource = new ClassPathResource(resourceClassPath);
    ApplicationContext context = new ClassPathXmlApplicationContext(resource.getPath());

    Component component = (Component) context.getBean(componentBean);
    component.start();
}

From source file:com.gvmax.web.WebMain.java

@SuppressWarnings("deprecation")
public static void main(String[] args) {
    try {/*  ww  w.  ja v  a 2 s . c o  m*/
        MetricRegistry registry = MetricsUtil.getRegistry();
        Properties props = new Properties();
        props.load(new ClassPathResource("/web.properties").getInputStream());

        int httpPort = Integer.parseInt(props.getProperty("web.http.port", "19080"));
        int httpsPort = Integer.parseInt(props.getProperty("web.https.port", "19443"));
        logger.info("Starting server: " + httpPort + " :: " + httpsPort);

        Server server = new Server(httpPort);
        ThreadPool threadPool = new InstrumentedQueuedThreadPool(registry);
        server.setThreadPool(threadPool);

        // Setup HTTPS
        if (new File("gvmax.jks").exists()) {
            SslSocketConnector connector = new SslSocketConnector();
            connector.setPort(httpsPort);
            connector.setKeyPassword(props.getProperty("web.keystore.password"));
            connector.setKeystore("gvmax.jks");
            server.addConnector(connector);
        } else {
            logger.warn("keystore gvmax.jks not found, ssl disabled");
        }

        // Setup WEBAPP
        URL warUrl = WebMain.class.getClassLoader().getResource("webapp");
        String warUrlString = warUrl.toExternalForm();
        WebAppContext ctx = new WebAppContext(warUrlString, "/");
        ctx.setAttribute(MetricsServlet.METRICS_REGISTRY, registry);
        InstrumentedHandler handler = new InstrumentedHandler(registry, ctx);
        server.setHandler(handler);
        server.start();
        server.join();
    } catch (Exception e) {
        logger.error(e);
        System.exit(0);
    }
}

From source file:org.restlet.example.book.restlet.ch03.sec3.server.MailServerSpring.java

public static void main(String[] args) throws Exception {
    // Load the Spring container
    ClassPathResource resource = new ClassPathResource(
            "org/restlet/example/book/restlet/ch04/sec3/server/component-spring.xml");
    BeanFactory factory = new XmlBeanFactory(resource);

    // Start the Restlet component
    Component component = (Component) factory.getBean("component");
    component.start();/*from w  w w  .ja v a2 s .co  m*/
}