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

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

Introduction

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

Prototype

public StaticApplicationContext(@Nullable ApplicationContext parent) throws BeansException 

Source Link

Document

Create a new StaticApplicationContext with the given parent.

Usage

From source file:org.terasoluna.gfw.web.codelist.CodeListInterceptorTest.java

@Before
public void setUp() {
    this.testTarget = new CodeListInterceptor();
    testTarget.setApplicationContext(new StaticApplicationContext(getApplicationContext()));

    this.mockRequest = new MockHttpServletRequest();
    this.mockResponse = new MockHttpServletResponse();

    @SuppressWarnings("unchecked")
    Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    this.mockAppender = mockAppender;
    Logger logger = (Logger) LoggerFactory.getLogger(CodeListInterceptor.class);
    logger.addAppender(mockAppender);/*from w w w  .j a v a2  s  .  c om*/
}

From source file:org.jboss.arquillian.spring.integration.enricher.AbstractSpringInjectionEnricher.java

/**
 * <p>Injects dependencies into the test case.</p>
 *
 * @param applicationContext the {@link org.springframework.context.ApplicationContext}
 * @param testCase           the test case for which the beans will be injected
 *///  w  w  w  .ja  v  a  2  s.  co  m
private void injectDependencies(ApplicationContext applicationContext, Object testCase) {
    // for applications that do not contain Annotation post processors, create new
    // application context with those and create test class from that context
    StaticApplicationContext staticContext = new StaticApplicationContext(applicationContext);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(staticContext);
    staticContext.refresh();

    // retrieves the bean factory
    AutowireCapableBeanFactory beanFactory = staticContext.getAutowireCapableBeanFactory();
    // injects all the members
    beanFactory.autowireBeanProperties(testCase, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    // initialize the bean
    beanFactory.initializeBean(testCase, testCase.getClass().getName());
}

From source file:io.milton.servlet.SpringMiltonFilter.java

@SuppressWarnings("resource")
protected void initSpringApplicationContext(FilterConfig fc) {

    final WebApplicationContext rootContext = WebApplicationContextUtils
            .getWebApplicationContext(fc.getServletContext());

    StaticApplicationContext parent;// ww  w.  j  a  va  2s  . co m
    if (rootContext != null) {
        log.info("Found a root spring context, and using it");
        parent = new StaticApplicationContext(rootContext);
    } else {
        log.info("No root spring context");
        parent = new StaticApplicationContext();
    }

    final FilterConfigWrapper configWrapper = new FilterConfigWrapper(fc);
    parent.getBeanFactory().registerSingleton("config", configWrapper);
    parent.getBeanFactory().registerSingleton("servletContext", fc.getServletContext());
    File webRoot = new File(fc.getServletContext().getRealPath("/"));
    parent.getBeanFactory().registerSingleton("webRoot", webRoot);
    log.info("Registered root webapp path in: webroot=" + webRoot.getAbsolutePath());
    parent.refresh();

    final String configClass = fc.getInitParameter("contextConfigClass");
    final String sFiles = fc.getInitParameter("contextConfigLocation");

    ConfigurableApplicationContext ctx = null;
    if (StringUtils.isNotBlank(configClass)) {
        try {
            Class<?> clazz = Class.forName(configClass);
            final AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext();
            annotationCtx.setParent(parent);
            annotationCtx.register(clazz);
            annotationCtx.refresh();
            ctx = annotationCtx;
        } catch (ClassNotFoundException e) {
            ctx = null;
            log.error("Unable to create a child context for Milton", e);
        }
    } else {
        String[] contextFiles;
        if (sFiles != null && sFiles.trim().length() > 0) {
            contextFiles = sFiles.split(" ");
        } else {
            contextFiles = new String[] { "applicationContext.xml" };
        }

        try {
            ctx = new ClassPathXmlApplicationContext(contextFiles, parent);
        } catch (BeansException e) {
            log.error("Unable to create a child context for Milton", e);
        }
    }

    if (ctx == null) {
        log.warn("No child context available, only using parent context");
        context = parent;
    } else {
        context = ctx;
    }

}

From source file:org.marketcetera.orderloader.Main.java

/**
 * Reads the orders from the supplied and sends them to the server.
 *
 * @throws Exception if there were errors.
 *///from w w  w .  j a v a 2 s .  c o  m
protected void doProcessing() throws Exception {
    //Create the order processor
    StaticApplicationContext context = new StaticApplicationContext(
            new FileSystemXmlApplicationContext(CFG_BASE_FILE_NAME));
    String clientURL = (String) context.getBean("clientURL"); //$NON-NLS-1$
    String clientWSHost = (String) context.getBean("clientWSHost"); //$NON-NLS-1$
    Integer clientWSPort = (Integer) context.getBean("clientWSPort"); //$NON-NLS-1$
    String clientIDPrefix = (String) context.getBean("clientIDPrefix"); //$NON-NLS-1$
    ClientParameters parameters = new ClientParameters(mAuthentication.getUser(), mAuthentication.getPassword(),
            clientURL, clientWSHost, clientWSPort, clientIDPrefix);
    OrderProcessor processor = createProcessor(parameters);
    //Run the order loader and display the summary of results.
    try {
        displaySummary(new OrderLoader(mMode, mBrokerID, processor, new File(mFileName)));
    } finally {
        processor.done();
    }
}