Package org.springframework.context.support

Examples of org.springframework.context.support.GenericXmlApplicationContext


public class TransferScript {

  public static void main(String... args) throws InsufficientFundsException {

    ApplicationContext ctx =
      new GenericXmlApplicationContext("com/bank/config/app-config.xml");


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

    // generate a random amount between 10.00 and 90.00 dollars
    double amount = (new Random().nextInt(8) + 1) * 10;

    TransferReceipt receipt = transferService.transfer(amount, "A123", "C456");
View Full Code Here


public class ReproTests {

  @Test
  public void xml() {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:module.xml");
    ctx.refresh();
    Foo foo = ctx.getBean(Foo.class);
    assertNotNull(foo);
    ctx.close();
  }
View Full Code Here

    Logger logger = org.apache.log4j.Logger.getLogger(loggerName());

    Appender appender = nothingLoggedAppender();
    logger.addAppender(appender);
    try {
      GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
      ctx.load("classpath:org/springframework/issues/ReproTests-context.xml");
      ctx.refresh();

      ctx.getBean("foo");

      ctx.close();

    } finally {
      logger.removeAppender(appender);
    }
  }
View Full Code Here

  }

  @Test
  public void propertyPlaceholderEnvironmentProperties() throws Exception {
    MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    applicationContext.setEnvironment(env);
    applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
    applicationContext.refresh();
    Map<String, PlaceholderConfigurerSupport> beans = applicationContext
        .getBeansOfType(PlaceholderConfigurerSupport.class);
    assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty());
    String s = (String) applicationContext.getBean("string");
    assertEquals("No properties replaced", "spam", s);
  }
View Full Code Here

    context.close();
  }

  @Test
  public void configuredThroughNamespace() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertTrue(asyncThread.getName().startsWith("testExecutor"));

    TestableAsyncUncaughtExceptionHandler exceptionHandler =
        context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
    assertFalse("handler should not have been called yet", exceptionHandler.isCalled());

    testBean.failWithVoid();
    exceptionHandler.await(3000);
    Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
    exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
    context.close();
  }
View Full Code Here

*/
public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {

  @Override
  protected ConfigurableApplicationContext getApplicationContext() {
    return new GenericXmlApplicationContext(
        "/org/springframework/cache/config/annotationDrivenCacheNamespace.xml");
  }
View Full Code Here

    assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator());
  }

  @Test
  public void cacheResolver() {
    ConfigurableApplicationContext context = new GenericXmlApplicationContext(
        "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml");

    CacheInterceptor ci = context.getBean(CacheInterceptor.class);
    assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
    context.close();
  }
View Full Code Here

    context.close();
  }

  @Test
  public void bothSetOnlyResolverIsUsed() {
    ConfigurableApplicationContext context = new GenericXmlApplicationContext(
        "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml");

    CacheInterceptor ci = context.getBean(CacheInterceptor.class);
    assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
    context.close();
  }
View Full Code Here

    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
  }

  @Test
  public void genericXmlApplicationContext() {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    assertHasStandardEnvironment(ctx);
    ctx.setEnvironment(prodEnv);
    ctx.load(XML_PATH);
    ctx.refresh();

    assertHasEnvironment(ctx, prodEnv);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, prodEnv);
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
  }
View Full Code Here

  private GenericXmlApplicationContext context;

  @Test
  public void testJavaBean() {
    context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName()+"-java-context.xml");
    TestService bean = context.getBean("javaBean", TestService.class);
    LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);

    assertEquals(0, logAdvice.getCountThrows());
    try {
View Full Code Here

TOP

Related Classes of org.springframework.context.support.GenericXmlApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.