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

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

Introduction

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

Prototype

@Override
    public void refresh() throws BeansException, IllegalStateException 

Source Link

Usage

From source file:org.musa.tcpserver.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/serverContext.xml");

    context.registerShutdownHook();/*from  www  .  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();// www  .j  av  a2  s  .co  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();

    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 {//w  w  w .ja  va  2 s . 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 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.//from w  w w  . j a  v  a 2 s. 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);/*from  w w  w.j  a  v a2  s . c om*/
    appContext.refresh();
    ApplicationStack applicationStack = appContext.getBean("applicationStack", ApplicationStack.class);
    applicationStack.deploy();
    return applicationStack.getUrl();
}

From source file:org.cloudfoundry.identity.uaa.test.ParentContextLoader.java

@Override
protected void customizeContext(GenericApplicationContext context) {
    GenericXmlApplicationContext parent = new GenericXmlApplicationContext();
    parent.setEnvironment(TestProfileEnvironment.getEnvironment());
    parent.load(parentLocation);//from  ww  w .j  a  v  a  2 s . c  o m
    parent.refresh();
    super.customizeContext(context);
    context.setParent(parent);
}

From source file:com.bank.config.xml.IntegrationITCase.java

@Test
public void transferTenDollars() throws InsufficientFundsException {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    //ctx.getEnvironment().setActiveProfiles("dev");
    ctx.load("classpath:transfer-service-config.xml");
    ctx.refresh();

    TransferService transferService = ctx.getBean(TransferService.class);
    AccountRepository accountRepository = ctx.getBean(AccountRepository.class);

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(100.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00));

    transferService.transfer(10.00, "A123", "C456");

    assertThat(accountRepository.findById("A123").getBalance(), equalTo(90.00));
    assertThat(accountRepository.findById("C456").getBalance(), equalTo(10.00));
}

From source file:com.company.contactbook.service.ContactServiceImplTest.java

@Before
public void setUp() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.getEnvironment().setActiveProfiles("memory");
    context.load("classpath:/applicationContext.xml");
    context.refresh();
    contactService = context.getBean(ContactService.class);
}