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

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

Introduction

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

Prototype

@Override
public ConfigurableEnvironment getEnvironment() 

Source Link

Document

Return the Environment for this application context in configurable form, allowing for further customization.

Usage

From source file:org.springframework.data.neo4j.illegal.aspects.index1.IllegalIndex1Tests.java

/**
 * As the first illegal entity detected will blow up the application context - we need a way
 * to ensure only the illegal entity under test it loaded to assert that we fail
 * for the correct reason and in an appropriate way. This method will create and application
 * context ensuring that only the illegal entity under test (passed in as an argument), is
 * detected by the context.  This is currently done by wrapping each Illegal Entity bootstrap
 * logic in a Spring profile against its same name
 *
 * @param entityUnderTest Class which should be detected by SDN for the purposes of testing
 * @throws Throwable/*from ww w  .  j  a  va 2s  .  c  o m*/
 */
private void createAppCtxAndPropagateRootExceptionIfThrown(Class entityUnderTest) throws Throwable {
    try {
        ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext();
        appCtx.setConfigLocation(
                "org/springframework/data/neo4j/aspects/support/illegal-index1-tests-context.xml");
        appCtx.getEnvironment().setActiveProfiles(entityUnderTest.getSimpleName());
        appCtx.refresh();
    } catch (BeanCreationException bce) {
        throw ExceptionUtils.getRootCause(bce);
    }
}

From source file:org.springframework.data.neo4j.illegal.aspects.index2.IllegalIndex2Tests.java

/**
 * As the first illegal entity detected will blow up the application context - we need a way
 * to ensure only the illegal entity under test it loaded to assert that we fail
 * for the correct reason and in an appropriate way. This method will create and application
 * context ensuring that only the illegal entity under test (passed in as an argument), is
 * detected by the context.  This is currently done by wrapping each Illegal Entity bootstrap
 * logic in a Spring profile against its same name
 *
 * @param entityUnderTest Class which should be detected by SDN for the purposes of testing
 * @throws Throwable// w  w  w .j a v a  2  s  .  c  o m
 */
private void createAppCtxAndPropagateRootExceptionIfThrown(Class entityUnderTest) throws Throwable {
    try {
        ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext();
        appCtx.setConfigLocation(
                "org/springframework/data/neo4j/aspects/support/illegal-index2-tests-context.xml");
        appCtx.getEnvironment().setActiveProfiles(entityUnderTest.getSimpleName());
        appCtx.refresh();
    } catch (BeanCreationException bce) {
        throw ExceptionUtils.getRootCause(bce);
    }
}

From source file:org.springframework.xd.dirt.launcher.RedisContainerLauncher.java

/**
 * Create a container instance/* w  w  w  .  java 2s  . c o  m*/
 * @param options
 */
@SuppressWarnings("resource")
public static Container create(ContainerOptions options) {
    ClassPathXmlApplicationContext context = null;
    try {
        context = new ClassPathXmlApplicationContext();
        context.setConfigLocation(LAUNCHER_CONFIG_LOCATION);
        //TODO: Need to sort out how this will be handled consistently among launchers
        if (!options.isJmxDisabled()) {
            context.getEnvironment().addActiveProfile("xd.jmx.enabled");
            OptionUtils.setJmxProperties(options, context.getEnvironment());
        }
        context.refresh();
    } catch (BeanCreationException e) {
        if (e.getCause() instanceof RedisConnectionFailureException) {
            logger.fatal(e.getCause().getMessage());
            System.err.println("Redis does not seem to be running. Did you install and start Redis? "
                    + "Please see the Getting Started section of the guide for instructions.");
            System.exit(1);
        }
    }
    context.registerShutdownHook();
    ContainerLauncher launcher = context.getBean(ContainerLauncher.class);
    Container container = launcher.launch(options);
    return container;
}

From source file:org.springframework.xd.perftest.PerformanceTest.java

public static void main(String[] args) {
    updatePerfTestHome();/* w  w  w .  j  a  v  a2 s .  c om*/
    PerformanceTest perfTest = new PerformanceTest();
    CmdLineOptions options = perfTest.new CmdLineOptions();
    CmdLineParser parser = new CmdLineParser(options);
    parser.setUsageWidth(90);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        parser.printUsage(System.err);
        System.exit(1);
    }
    transport = options.getTransport();
    consumerType = options.getConsumerType();
    flow = options.getFlow();
    setConnectionFactoryType(options.getConnectionFactoryType());
    if (options.isShowHelp()) {
        parser.printUsage(System.err);
        System.exit(0);
    }
    logger.info("*******Starting Performance test********");
    logger.info("Transport: " + transport);
    if (flow.equals(Flow.inbound)) {
        logger.info("Consumer:  " + consumerType);
    }
    logger.info("ConnectionFactory: " + options.getConnectionFactoryType());
    logger.info("****************************************");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.getEnvironment().setActiveProfiles(consumerType.name());
    context.setConfigLocation("META-INF/perftest/" + transport + "-perftest-" + options.getFlow() + ".xml");
    context.refresh();
    context.registerShutdownHook();

}