Search in sources :

Example 86 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.

the class ClassPathBeanDefinitionScannerScopeIntegrationTests method sessionScopeWithNoProxy.

@Test
public void sessionScopeWithNoProxy() {
    RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
    ApplicationContext context = createContext(NO);
    ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
    // not a proxy so this should not have changed
    assertEquals(MODIFIED_NAME, bean.getName());
    // but a newly retrieved bean should have the default name
    ScopedTestBean bean2 = (ScopedTestBean) context.getBean("session");
    assertEquals(DEFAULT_NAME, bean2.getName());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.Test)

Example 87 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.

the class ClassPathBeanDefinitionScannerScopeIntegrationTests method sessionScopeWithProxiedTargetClass.

@Test
public void sessionScopeWithProxiedTargetClass() {
    RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
    ApplicationContext context = createContext(TARGET_CLASS);
    IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
    // should be a class-based proxy
    assertTrue(AopUtils.isCglibProxy(bean));
    assertTrue(bean instanceof ScopedTestBean);
    assertTrue(bean instanceof SessionScopedTestBean);
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
    // this is a proxy so it should be reset to default
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    IScopedTestBean bean2 = (IScopedTestBean) context.getBean("session");
    assertEquals(MODIFIED_NAME, bean2.getName());
    bean2.setName(DEFAULT_NAME);
    assertEquals(DEFAULT_NAME, bean.getName());
    RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
    assertEquals(MODIFIED_NAME, bean.getName());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.Test)

Example 88 with ApplicationContext

use of org.springframework.context.ApplicationContext in project centipede by paulhoule.

the class CentipedeShell method parseOptions.

private CentipedeShellOptions parseOptions(String[] arguments) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    ApplicationContext bootstrapContext = newContext(getBootstrapApplicationContextPath());
    OptionParser parser = new OptionParser(CentipedeShellOptions.class);
    wireupOptionParser(bootstrapContext, parser);
    closeContext(bootstrapContext);
    return (CentipedeShellOptions) parser.parse(newArrayList(arguments));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) OptionParser(com.ontology2.centipede.parser.OptionParser)

Example 89 with ApplicationContext

use of org.springframework.context.ApplicationContext in project centipede by paulhoule.

the class StaticCentipedeShellTest method defaultEvaluationIsDefinedInFiles.

@Test
public void defaultEvaluationIsDefinedInFiles() {
    ApplicationContext c = newContext(objectCountingContext());
    assertEquals(1, ObjectThatCountsClassInstances.get());
    Object that = c.getBean("l");
    assertEquals(2, ObjectThatCountsClassInstances.get());
    ((AbstractApplicationContext) c).close();
    assertEquals(0, ObjectThatCountsClassInstances.get());
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Test(org.junit.Test)

Example 90 with ApplicationContext

use of org.springframework.context.ApplicationContext in project sharding-jdbc by dangdangdotcom.

the class SpringNamespaceWithMasterSlaveMain method main.

// CHECKSTYLE:OFF
public static void main(final String[] args) throws SQLException {
    // CHECKSTYLE:ON
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/applicationContextWithMasterSlave.xml");
    OrderService orderService = applicationContext.getBean(OrderService.class);
    orderService.insert();
    orderService.select();
    orderService.delete();
    orderService.select();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) OrderService(com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.service.OrderService)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13