Example usage for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext

Introduction

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

Prototype

public FileSystemXmlApplicationContext(String... configLocations) throws BeansException 

Source Link

Document

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Usage

From source file:com.uvigo.kurento.ims.RecorderSipServlet.java

public RecorderSipServlet() {
    //Create the Spring context
    ApplicationContext context = new FileSystemXmlApplicationContext(
            new String[] { "file:/home/pcounhago/kmf-media-config.xml" });
    //Inject the MediaPipelineFactory bean
    mpf = context.getBean(MediaPipelineFactory.class);
    //MediaPipeline
    mp = mpf.create();//from w w  w. j av a2s. c o  m
}

From source file:schemacrawler.tools.integration.spring.SchemaCrawlerSpringCommandLine.java

@Override
public void execute() throws Exception {
    final Path contextFile = Paths.get(springOptions.getContextFileName()).normalize().toAbsolutePath();
    final ApplicationContext appContext;
    if (exists(contextFile)) {
        final String contextFilePath = contextFile.toUri().toString();
        LOGGER.log(Level.INFO, "Loading context from file, " + contextFilePath);
        appContext = new FileSystemXmlApplicationContext(contextFilePath);
    } else {/* ww w . ja  v  a  2s  .c om*/
        LOGGER.log(Level.INFO, "Loading context from classpath, " + springOptions.getContextFileName());
        appContext = new ClassPathXmlApplicationContext(springOptions.getContextFileName());
    }

    try {
        final DataSource dataSource = (DataSource) appContext.getBean(springOptions.getDataSourceName());
        try (Connection connection = dataSource.getConnection();) {
            final Executable executable = (Executable) appContext.getBean(springOptions.getExecutableName());
            executable.execute(connection);
        }
    } finally {
        ((AbstractXmlApplicationContext) appContext).close();
    }
}

From source file:org.asqatasun.websnapshot.utils.AbstractDaoTestCase.java

public AbstractDaoTestCase(String testName, String inputDataFileName) {
    super(testName);

    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, DATABASE);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, USER);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, PASSWORD);
    ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext(SPRING_FILE_PATH);
    springBeanFactory = springApplicationContext;
    this.inputDataFileName = inputDataFileName;
}

From source file:org.apache.ftpserver.main.Daemon.java

/**
 * Get the configuration object.//w w w.ja  v  a  2s .c o m
 */
private static FtpServer getConfiguration(String[] args) throws Exception {

    FtpServer server = null;
    if (args == null || args.length < 2) {
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if ((args.length == 2) && args[1].equals("--default")) {
        LOG.info("Using default configuration....");
        server = new FtpServerFactory().createServer();
    } else if (args.length == 2) {
        LOG.info("Using xml configuration file " + args[1] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]);

        if (ctx.containsBean("server")) {
            server = (FtpServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
            if (beanNames.length == 1) {
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.out
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (FtpServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        throw new FtpException("Invalid configuration option");
    }

    return server;
}

From source file:de.uzk.hki.da.at.AcceptanceTest.java

private static void instantiateRepository(Properties properties) {

    String repImplBeanName = properties.getProperty("cb.implementation.repository");
    if (repImplBeanName == null)
        repImplBeanName = "fakeRepositoryFacade";

    AbstractApplicationContext context = new FileSystemXmlApplicationContext("conf/beans.xml");
    repositoryFacade = (RepositoryFacade) context.getBean(repImplBeanName);
    context.close();//  ww  w .j  a va  2 s  .  c  om
}

From source file:gov.nih.nci.cdmsconnector.test.EnrollPatientTest.java

public void testEnrollPatientAPI() throws IOException, Exception {
    RegisterSubjectRequest request = getPopulatedEnrollPatientRequest();

    String beansFilePath = System.getProperty("catalina.home") + "/conf/c3d/applicationContext.xml";
    ApplicationContext ctx = new FileSystemXmlApplicationContext(beansFilePath);

    ClinicalConnectorImpl impl = (ClinicalConnectorImpl) ctx.getBean("c3DGridService");

    RegisterSubjectResponse response = impl.registerSubject(request);

    StringWriter writer = new StringWriter();
    Utils.serializeObject(response, new QName("EnrollPatientResponse"), writer);

    responseStr = writer.getBuffer().toString();
    log.debug(responseStr);/*www  . ja  v  a 2 s.co  m*/

}

From source file:org.apache.asyncweb.spring.Main.java

public void start() {
    String[] configs = new String[] { configDir + "conf/AsyncWeb.xml",
            configDir + "conf/" + serviceConfigName + "/*.xml" };
    ApplicationContext ctx = new FileSystemXmlApplicationContext(configs);
    ServiceContainer container = (ServiceContainer) ctx.getBean("container");
    try {//  ww  w. ja v  a  2  s .c om
        container.start();
    } catch (ContainerLifecycleException e) {
        LOG.error("Failed to start container", e);
        System.exit(1);
    }
    LOG.info("AsyncWeb server started");
}

From source file:org.opens.tgol.entity.dao.test.AbstractDaoTestCase.java

public AbstractDaoTestCase(String testName) {
    super(testName);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, DATABASE);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, USER);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, PASSWORD);
    ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext(SPRING_FILE_PATH);
    springBeanFactory = springApplicationContext;
}

From source file:org.openvpms.report.tools.ReportTool.java

/**
 * Constructs a {@link ReportTool}.//from  w  ww  .j a  va2s.  co  m
 *
 * @param contextPath the application context path
 */
public ReportTool(String contextPath) {
    ApplicationContext context;
    if (!new File(contextPath).exists()) {
        context = new ClassPathXmlApplicationContext(contextPath);
    } else {
        context = new FileSystemXmlApplicationContext(contextPath);
    }
    service = (IArchetypeService) context.getBean("archetypeService");
    lookups = context.getBean(ILookupService.class);
    handlers = context.getBean(DocumentHandlers.class);
    functions = context.getBean(ArchetypeFunctionsFactory.class);
    this.factory = new ReportFactory(service, lookups, handlers, functions);
}

From source file:org.opennms.features.vaadin.pmatrix.manual.AppContextSpecificationMarshalTest.java

public void testAppContext() {
    System.out.println("starting testAppContext");
    appContext = new FileSystemXmlApplicationContext("/src/test/resources/testApplicationContext.xml");

    //PmatrixSpecification pmatrixSpec = (PmatrixSpecification) appContext.getBean("pmatrixSpecification");
    PmatrixSpecificationList pmatrixSpecificationList = (PmatrixSpecificationList) appContext
            .getBean("pmatrixSpecificationList");

    System.out.println(pmatrixSpecificationList);

    System.out.println("test finished ending testAppContext");
}