Example usage for org.springframework.context.support GenericXmlApplicationContext load

List of usage examples for org.springframework.context.support GenericXmlApplicationContext load

Introduction

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

Prototype

public void load(String... resourceLocations) 

Source Link

Document

Load bean definitions from the given XML resources.

Usage

From source file:com.richard.memorystore.tcp.TcpServer.java

public static GenericXmlApplicationContext setupContext() {
    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.print("Detect open server socket...");
    int availableServerSocket = SocketUtils.findAvailableServerSocket(5678);

    final Map<String, Object> sockets = new HashMap<String, Object>();
    sockets.put("availableServerSocket", availableServerSocket);

    final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);

    context.getEnvironment().getPropertySources().addLast(propertySource);

    System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket"));

    context.load("classpath:tcpClientServerDemo-context.xml");
    context.registerShutdownHook();/*w ww  .j  a v  a 2  s  .c o m*/
    context.refresh();

    return context;
}

From source file:com.haythem.integration.Main.java

public static GenericXmlApplicationContext setupContext() {
    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.print("Detect open server socket...");
    int availableServerSocket = SocketUtils.findAvailableServerSocket(5678);

    final Map<String, Object> sockets = new HashMap<String, Object>();
    sockets.put("availableServerSocket", availableServerSocket);

    final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);

    context.getEnvironment().getPropertySources().addLast(propertySource);

    System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket"));

    context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
    context.registerShutdownHook();/*from w w  w.j  ava  2  s .c o m*/
    context.refresh();

    return context;
}

From source file:org.musa.tcpclients.Main.java

public static GenericXmlApplicationContext setupContext() {
    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.print("Detect open server socket...");
    int availableServerSocket = SocketUtils.findAvailableServerSocket(5683);

    final Map<String, Object> sockets = new HashMap<String, Object>();
    sockets.put("availableServerSocket", availableServerSocket);

    final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);

    context.getEnvironment().getPropertySources().addLast(propertySource);

    System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket"));

    context.load("classpath:META-INF/spring/integration/clientContext.xml");
    //context.registerShutdownHook();
    context.refresh();/*from   ww w. ja v a 2s .  c  om*/

    return context;
}

From source file:com.tcp.client.Main.java

public static GenericXmlApplicationContext setupContext() throws InterruptedException, IOException {

    int availableServerSocket = 5682;
    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    System.out.println("===== Player 2 =====");

    while (true) {
        try {//from  www  . j  a  va2s.c  o  m
            ServerSocket s = new ServerSocket(availableServerSocket);
            s.close();
            System.out.println("Player 1 is unavailable.. trying again!!");
            Thread.sleep(2000);

        } catch (IOException e) {
            System.out.println("Found player 1!!");
            break;
        }
    }

    final Map<String, Object> sockets = new HashMap<String, Object>();
    sockets.put("availableServerSocket", availableServerSocket);

    final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);

    context.getEnvironment().getPropertySources().addLast(propertySource);
    context.load("classpath:META-INF/context.xml");
    context.registerShutdownHook();
    context.refresh();

    return context;
}

From source file:solidstack.template.Spring.java

@Test
public void testSpring() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:/solidstack/template/context.xml");
    context.refresh();/*from   w  w w  . jav a 2s  .co m*/
}

From source file:ReproTests.java

/**
 * Test will fail as two PropertyPlaceholderConfigurer beans are defined, with one
 * depending on the other for placeholder resolution.  This is a lifecycle issue with
 * the way BeanFactoryPostProcessors are processed.  See {@link #workaround()} below
 * for a solution to this.//  ww  w  .  j a va  2s  .c  o  m
 */
@Test
public void repro() {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("ReproTests-repro.xml");
    ctx.refresh();
}

From source file:com.amazonaws.services.simpleworkflow.flow.examples.deployment.DeploymentWorkflowImpl.java

@Override
public Promise<String> deploy(String springTemplate) {
    Resource templateResource = new ByteArrayResource(springTemplate.getBytes());
    GenericXmlApplicationContext appContext = new GenericXmlApplicationContext();
    appContext.setParent(applicationContext);
    appContext.load(templateResource);
    appContext.refresh();//from   w w  w.j  a  v  a  2 s. c  om
    ApplicationStack applicationStack = appContext.getBean("applicationStack", ApplicationStack.class);
    applicationStack.deploy();
    return applicationStack.getUrl();
}

From source file:org.cloudfoundry.identity.varz.BootstrapTests.java

private GenericXmlApplicationContext getServletContext(String... resources) {

    String profiles = null;/*w  w  w.  j a v  a2  s  .  c om*/
    String[] resourcesToLoad = resources;
    if (!resources[0].endsWith(".xml")) {
        profiles = resources[0];
        resourcesToLoad = new String[resources.length - 1];
        System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length);
    }

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(resourcesToLoad);

    if (profiles != null) {
        context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
    }

    // Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(
            new Resource[] { new FileSystemResource("./src/test/resources/test/config/varz.yml") });
    context.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("servletProperties", factory.getObject()));

    context.refresh();

    return context;

}

From source file:org.cloudfoundry.identity.login.BootstrapTests.java

private GenericXmlApplicationContext getServletContext(String... resources) {

    String profiles = null;/*from  w  w w .j  a v a2  s .  c o m*/
    String[] resourcesToLoad = resources;
    if (!resources[0].endsWith(".xml")) {
        profiles = resources[0];
        resourcesToLoad = new String[resources.length - 1];
        System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length);
    }

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(resourcesToLoad);

    if (profiles != null) {
        context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
    }

    // Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(
            new Resource[] { new FileSystemResource("./src/test/resources/test/config/login.yml") });
    context.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("servletProperties", factory.getObject()));

    context.refresh();

    return context;

}

From source file:org.cloudfoundry.identity.batch.BootstrapTests.java

private GenericXmlApplicationContext getServletContext(String... resources) {

    String profiles = null;/*w w w .  j ava 2  s  .  c  om*/
    String[] resourcesToLoad = resources;
    if (!resources[0].endsWith(".xml")) {
        profiles = resources[0];
        resourcesToLoad = new String[resources.length - 1];
        System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length);
    }

    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(resourcesToLoad);

    if (profiles != null) {
        context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
    }

    // Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(
            new Resource[] { new FileSystemResource("./src/test/resources/test/config/batch.yml") });
    context.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("servletProperties", factory.getObject()));

    context.refresh();

    return context;

}