Example usage for org.springframework.context.support ClassPathXmlApplicationContext close

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext close.

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:com.dangdang.config.service.easyzk.demo.spring.MainEntrance.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = null;
    try {/*  w ww .j  ava 2 s. c  o m*/
        context = new ClassPathXmlApplicationContext("classpath:config-toolkit-simple.xml");
        context.registerShutdownHook();
        context.start();

        ExampleBeanWithConfigNode bean = context.getBean(ExampleBeanWithConfigNode.class);
        while (true) {
            bean.someMethod();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                //
            }
        }
    } finally {
        if (context != null) {
            context.close();
        }
    }
}

From source file:net.sf.gazpachoquest.extractor.dbunit.DBUnitDataExtractorRunner.java

public static void main(final String[] args) throws Exception {
    String dbEngine = "db_postgres";
    logger.info("Extracting data from {} database in DBUnit format", dbEngine);

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles("postgres", dbEngine);
    ctx.refresh();//from w  ww .j a  v a 2 s .  co m
    ctx.setConfigLocations(
            new String[] { "dbunitextractor-datasource-context.xml", "dbunitextractor-context.xml" });
    /*-
    ctx.getEnvironment().getPropertySources()
        .addLast(new ResourcePropertySource(String.format("classpath:/database/%s.properties", dbEngine))); */
    ctx.refresh();

    DBUnitDataExtractor extractor = (DBUnitDataExtractor) ctx.getBean("dbUnitDataExtractor");
    extractor.extract();
    ctx.close();

    logger.info("Done successfully. Check your target directory");

}

From source file:org.fusesource.cloudmix.tests.consumer.Main.java

public static void main(String[] args) {
    if (args.length > 0 && args[0].equals("-debug")) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }/*w ww  .ja  v a  2  s .  com*/
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/context.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:org.fusesource.cloudmix.tests.broker.Main.java

public static void main(String[] args) {
    if (verbose || (args.length > 0 && args[0].equals("-debug"))) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//from   w w w . j  a  v a 2 s. c o m
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/activemq.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:th.ac.chandra.eduqa.rest.application.Main.java

public static void main(String[] args) throws Exception {
    // Load the Spring application context
    final ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
            new String[] { "th/ac/chandra/eduqa/rest/config/applicationContext-common.xml",
                    "th/ac/chandra/eduqa/rest/config/applicationContext-hibernate.xml",
                    "th/ac/chandra/eduqa/rest/config/applicationContext-eduqa-resource.xml",
                    "th/ac/chandra/eduqa/rest/config/applicationContext-root-router.xml",
                    "th/ac/chandra/eduqa/rest/config/applicationContext-server.xml" });

    // Obtain the Restlet component from the Spring context and start it
    ((Component) springContext.getBean("top")).start();
    springContext.close();
    /*   applicationContext-bps-resource.xml
         applicationContext-common.xml//from w w  w  .ja  va 2s  .  c  o m
         applicationContext-hibernate.xml
         applicationContext-root-router.xml
         applicationContext-server.xml*/
    //testXStream();
}

From source file:raymond.mockftpserver.S3CachedFtpServer.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

    String identityPath = (String) ctx.getBean("identityPath");
    String charset = (String) ctx.getBean("charset");
    String keyBase = (String) ctx.getBean("keyBase");
    // String host = (String) ctx.getBean("s3Host");
    String bucket = (String) ctx.getBean("s3Bucket");
    String chave = (String) ctx.getBean("chave");
    Region region = (Region) ctx.getBean("s3Region");

    ctx.close();

    // check if user wants to create credentials
    File _accessFile = new File(identityPath);

    S3CachedFtpServer s3FtpServer = new S3CachedFtpServer();
    s3FtpServer.init(_accessFile, chave, charset, keyBase, bucket, region);

    if (!_accessFile.exists() && args.length != 2) {
        throw new RuntimeException("sem credenciais");
    } else if (!_accessFile.exists()) {
        s3FtpServer.writeKeyFile(args[0], args[1].toCharArray());
    }/*w w  w  .  j av  a  2  s  .c  om*/

    s3FtpServer.go();
}

From source file:com.codeasylum.stress.ui.Jormungandr.java

public static void main(String... args) {

    boolean init = false;

    try {//from  ww  w  .  j av a2  s . com
        new ExtendedTaskLoader();
        init = true;
    } catch (Exception exception) {
        JavaErrorDialog.showJavaErrorDialog(null, null, exception);
    }

    if (init) {

        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/codeasylum/stress/api/logging.xml", "com/codeasylum/stress/ui/jormungandr.xml");

        Jormungandr jormungandr = applicationContext.getBean("jormungandr", Jormungandr.class);

        try {
            jormungandr.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {

                    applicationContext.close();

                }
            });

            jormungandr.init().setVisible(true);
        } catch (Exception exception) {
            JavaErrorDialog.showJavaErrorDialog(jormungandr, jormungandr, exception);
            jormungandr.dispose();
        }
    }
}

From source file:com.digitalgeneralists.assurance.Application.java

public static void main(String[] args) {
    Logger logger = Logger.getLogger(Application.class);

    logger.info("App is starting.");

    Properties applicationProperties = new Properties();
    String applicationInfoFileName = "/version.txt";
    InputStream inputStream = Application.class.getResourceAsStream(applicationInfoFileName);
    applicationInfoFileName = null;//w  ww . ja  va2s.c o m

    try {
        if (inputStream != null) {
            applicationProperties.load(inputStream);

            Application.applicationShortName = applicationProperties.getProperty("name");
            Application.applicationName = applicationProperties.getProperty("applicationName");
            Application.applicationVersion = applicationProperties.getProperty("version");
            Application.applicationBuildNumber = applicationProperties.getProperty("buildNumber");

            applicationProperties = null;
        }
    } catch (IOException e) {
        logger.warn("Could not load application version information.", e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            logger.error("Couldn't close the application version input stream.");
        }
        inputStream = null;
    }

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        private Logger logger = Logger.getLogger(Application.class);

        public void run() {
            logger.info("Starting the Swing run thread.");

            try {
                Application.installDb();
            } catch (IOException e) {
                logger.fatal("Unable to install the application database.", e);
                System.exit(1);
            } catch (SQLException e) {
                logger.fatal("Unable to install the application database.", e);
                System.exit(1);
            }

            IApplicationUI window = null;
            ClassPathXmlApplicationContext springContext = null;
            try {
                springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml");
                StringBuffer message = new StringBuffer(256);
                logger.info(message.append("Spring Context: ").append(springContext));
                message.setLength(0);
                window = (IApplicationUI) springContext.getBean("ApplicationUI");
            } finally {
                if (springContext != null) {
                    springContext.close();
                }
                springContext = null;
            }

            if (window != null) {
                logger.info("Launching the window.");
                window.display();
            } else {
                logger.fatal("The main application window object is null.");
            }

            logger = null;
        }
    });
}

From source file:com.example.spring.app.ORMMain.java

public static void main(String[] args) {

    //Create Spring application context
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring/application-context.xml");

    //Get service from context. (service's dependency (ProductDAO) is autowired in ProductService)
    ProductService productService = ctx.getBean(ProductService.class);

    //Do some data operation
    productService.add(new Product(1, "Bulb"));
    productService.add(new Product(2, "Dijone mustard"));

    System.out.println("listAll: " + productService.listAll());

    //Test transaction rollback (duplicated key)
    try {// ww w.  jav  a 2  s  .  co m
        productService.addAll(
                Arrays.asList(new Product(3, "Book"), new Product(4, "Soap"), new Product(1, "Computer")));
    } catch (DataAccessException dataAccessException) {
    }

    //Test element list after rollback
    System.out.println("listAll: " + productService.listAll().size());

    ctx.close();

}

From source file:com.codeasylum.liquibase.Liquidate.java

public static void main(String... args) {

    ExtendedProfileLoader extensionLoader = null;
    boolean init = false;

    try {//w  w w.  ja  v a  2  s .  com
        extensionLoader = new ExtendedProfileLoader();
        init = true;
    } catch (Exception exception) {
        JavaErrorDialog.showJavaErrorDialog(null, null, exception);
    }

    if (init) {

        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/codeasylum/liquibase/liquidate.xml");

        Liquidate liquidate = applicationContext.getBean("liquidate", Liquidate.class);

        try {
            liquidate.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {

                    applicationContext.close();

                }
            });

            liquidate.init(extensionLoader).setVisible(true);
        } catch (Exception exception) {
            JavaErrorDialog.showJavaErrorDialog(liquidate, liquidate, exception);
            liquidate.dispose();
        }
    }
}