Search in sources :

Example 91 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project grails-core by grails.

the class UrlMappingsHolderFactoryBean method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    Assert.state(applicationContext != null, "Property [applicationContext] must be set!");
    Assert.state(grailsApplication != null, "Property [grailsApplication] must be set!");
    List urlMappings = new ArrayList();
    List excludePatterns = new ArrayList();
    GrailsClass[] mappings = grailsApplication.getArtefacts(UrlMappingsArtefactHandler.TYPE);
    final DefaultUrlMappingEvaluator mappingEvaluator = new DefaultUrlMappingEvaluator(applicationContext);
    mappingEvaluator.setPluginManager(pluginManager);
    if (mappings.length == 0) {
        urlMappings.addAll(mappingEvaluator.evaluateMappings(DefaultUrlMappings.getMappings()));
    } else {
        for (GrailsClass mapping : mappings) {
            GrailsUrlMappingsClass mappingClass = (GrailsUrlMappingsClass) mapping;
            List grailsClassMappings;
            if (Script.class.isAssignableFrom(mappingClass.getClazz())) {
                grailsClassMappings = mappingEvaluator.evaluateMappings(mappingClass.getClazz());
            } else {
                grailsClassMappings = mappingEvaluator.evaluateMappings(mappingClass.getMappingsClosure());
            }
            urlMappings.addAll(grailsClassMappings);
            if (mappingClass.getExcludePatterns() != null) {
                excludePatterns.addAll(mappingClass.getExcludePatterns());
            }
        }
    }
    DefaultUrlMappingsHolder defaultUrlMappingsHolder = new DefaultUrlMappingsHolder(urlMappings, excludePatterns, true);
    Config config = grailsApplication.getConfig();
    Integer cacheSize = config.getProperty(URL_MAPPING_CACHE_MAX_SIZE, Integer.class, null);
    if (cacheSize != null) {
        defaultUrlMappingsHolder.setMaxWeightedCacheCapacity(cacheSize);
    }
    Integer urlCreatorCacheSize = config.getProperty(URL_CREATOR_CACHE_MAX_SIZE, Integer.class, null);
    if (urlCreatorCacheSize != null) {
        defaultUrlMappingsHolder.setUrlCreatorMaxWeightedCacheCapacity(urlCreatorCacheSize);
    }
    // call initialize() after settings are in place
    defaultUrlMappingsHolder.initialize();
    UrlConverter urlConverter = applicationContext.containsBean(UrlConverter.BEAN_NAME) ? applicationContext.getBean(UrlConverter.BEAN_NAME, UrlConverter.class) : null;
    final GrailsControllerUrlMappings grailsControllerUrlMappings = new GrailsControllerUrlMappings(grailsApplication, defaultUrlMappingsHolder, urlConverter);
    ((ConfigurableApplicationContext) applicationContext).addApplicationListener(new ApplicationListener<ArtefactAdditionEvent>() {

        @Override
        public void onApplicationEvent(ArtefactAdditionEvent event) {
            GrailsClass artefact = event.getArtefact();
            if (artefact instanceof GrailsControllerClass) {
                grailsControllerUrlMappings.registerController((GrailsControllerClass) artefact);
            }
        }
    });
    urlMappingsHolder = grailsControllerUrlMappings;
}
Also used : GrailsControllerUrlMappings(org.grails.web.mapping.mvc.GrailsControllerUrlMappings) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GrailsControllerClass(grails.core.GrailsControllerClass) Config(grails.config.Config) ArrayList(java.util.ArrayList) GrailsUrlMappingsClass(grails.core.GrailsUrlMappingsClass) ArtefactAdditionEvent(grails.core.events.ArtefactAdditionEvent) GrailsClass(grails.core.GrailsClass) UrlConverter(grails.web.UrlConverter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 92 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project redisson by redisson.

the class SpringNamespaceWikiTest method testCluster.

@Test
public void testCluster() throws Exception {
    ClusterRunner clusterRunner = new ClusterRunner().addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6379).randomDir().nosave()).addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6380).randomDir().nosave()).addNode(new RedisRunner().requirepass("do_not_use_if_it_is_not_set").port(6381).randomDir().nosave());
    List<RedisRunner.RedisProcess> nodes = clusterRunner.run();
    try {
        ((ConfigurableApplicationContext) new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_cluster.xml")).close();
    } finally {
        for (RedisRunner.RedisProcess node : nodes) {
            node.stop();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClusterRunner(org.redisson.ClusterRunner) RedisRunner(org.redisson.RedisRunner) Test(org.junit.Test)

Example 93 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project redisson by redisson.

the class SpringNamespaceWikiTest method testReplicated.

@Test
public void testReplicated() throws Exception {
    RedisRunner.RedisProcess master = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").nosave().randomDir().run();
    RedisRunner.RedisProcess slave1 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6380).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    RedisRunner.RedisProcess slave2 = new RedisRunner().requirepass("do_not_use_if_it_is_not_set").masterauth("do_not_use_if_it_is_not_set").port(6381).nosave().randomDir().slaveof("127.0.0.1", 6379).run();
    try {
        ((ConfigurableApplicationContext) new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_replicated.xml")).close();
    } finally {
        master.stop();
        slave1.stop();
        slave2.stop();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RedisRunner(org.redisson.RedisRunner) Test(org.junit.Test)

Example 94 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project FizzBuzzEnterpriseEdition by EnterpriseQualityCoding.

the class FizzBuzzTest method setUp.

@Before
public void setUp() {
    final ApplicationContext context = new ClassPathXmlApplicationContext(TestConstants.SPRING_XML);
    this.fb = (FizzBuzz) context.getBean(TestConstants.STANDARD_FIZZ_BUZZ);
    this.out = System.out;
    ((ConfigurableApplicationContext) context).close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Before(org.junit.Before)

Example 95 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project FizzBuzzEnterpriseEdition by EnterpriseQualityCoding.

the class Main method main.

public static void main(final String[] args) {
    final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML);
    final FizzBuzz myFizzBuzz = (FizzBuzz) context.getBean(Constants.STANDARD_FIZZ_BUZZ);
    final FizzBuzzUpperLimitParameter fizzBuzzUpperLimit = new DefaultFizzBuzzUpperLimitParameter();
    myFizzBuzz.fizzBuzz(fizzBuzzUpperLimit.obtainUpperLimitValue());
    ((ConfigurableApplicationContext) context).close();
}
Also used : FizzBuzz(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DefaultFizzBuzzUpperLimitParameter(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.parameters.DefaultFizzBuzzUpperLimitParameter) DefaultFizzBuzzUpperLimitParameter(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.parameters.DefaultFizzBuzzUpperLimitParameter) FizzBuzzUpperLimitParameter(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.parameters.FizzBuzzUpperLimitParameter)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)177 Test (org.junit.Test)110 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)17 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 DataSource (javax.sql.DataSource)8 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)6 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4