Java Code Examples for org.springframework.context.annotation.AnnotationConfigApplicationContext#start()

The following examples show how to use org.springframework.context.annotation.AnnotationConfigApplicationContext#start() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void main(String[] args) throws InterruptedException {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
    context.start();

    UserRepository userRepository = (UserRepository) context.getBean("userRepository");
    CacheConfiguration cacheConfiguration = (CacheConfiguration) context.getBean("cacheConfiguration");

    while (true) {
        String name = userRepository.getUserCacheable(1L);
        System.out.println(String.format("name=%s", name));

        System.out.println(String.format("timeout=%s", cacheConfiguration.getTimeout()));
        TimeUnit.SECONDS.sleep(5);
    }

}
 
Example 2
private static void addPostprocessorAndUpdateContext(Class<?> currentVerticleClass,
    AnnotationConfigApplicationContext annotationConfigApplicationContext) {
    annotationConfigApplicationContext.addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass));
    annotationConfigApplicationContext.refresh();
    annotationConfigApplicationContext.start();
    annotationConfigApplicationContext.registerShutdownHook();
}
 
Example 3
Source Project: dubbo-2.6.5   File: AnnotationConsumer.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
    System.in.read();
}
 
Example 4
Source Project: dubbox   File: JavaConfigContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_JAVACONFIG;
    }
    context = new AnnotationConfigApplicationContext(configPath);
    context.start();
}
 
Example 5
Source Project: dubbo-samples   File: ProviderBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
    context.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 6
Source Project: dubbox   File: JavaConfigContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_JAVACONFIG;
    }
    context = new AnnotationConfigApplicationContext(configPath);
    context.start();
}
 
Example 7
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();

    AnnotationAction annotationAction = context.getBean("annotationAction", AnnotationAction.class);
    printServiceData();

    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
}
 
Example 8
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
    context.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 9
public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();

        AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
        String hello = annotationAction.doSayHello("world");
        System.out.println("result :" + hello);
//        annotationAction.sayCircuitBreaker("circuitBreaker");
        annotationAction.sayRateLimiter("rateLimiter", "Just Happy!");
    }
 
Example 10
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
    context.start();

    printServiceData();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 11
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();

    printServiceData();

    AnnotationAction annotationAction = context.getBean("annotationAction", AnnotationAction.class);
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
}
 
Example 12
Source Project: dubbox   File: JavaConfigContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_JAVACONFIG;
    }
    context = new AnnotationConfigApplicationContext(configPath);
    context.start();
}
 
Example 13
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();
    ZKTools.generateDubboProperties();

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
    context.start();

    printServiceData();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 14
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
    context.start();

    System.out.println("dubbo service started");
}
 
Example 15
Source Project: ShedLock   File: AopCleanupTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCloseTaskExecutor() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    context.start();
    context.close();
    assertThat(context.isActive()).isFalse();
}
 
Example 16
Source Project: chassis   File: MetadataCollectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    ConfigurationManager.getConfigInstance().setProperty("chassis.eureka.disable","true");
    ConfigurationManager.getConfigInstance().setProperty("eureka.metadata.prop1", "propValue");
    ConfigurationManager.getConfigInstance().setProperty("eureka.datacenter", "default");

    StandardEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(new ArchaiusSpringPropertySource());
    context = new AnnotationConfigApplicationContext();
    context.setEnvironment(environment);
    context.register(MetadataCollectorConfiguration.class);
    context.refresh();
    context.start();
}
 
Example 17
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
}
 
Example 18
public static void main(String[] args) throws InterruptedException {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
    context.start();

    log.info("service started successfully!");
    Runtime.getRuntime().addShutdownHook(new Thread(){
        @Override
        public void run() {
            log.info("Shutdown hook was invoked. Shutting down Service.");
            context.close();
        }
    });
    CountDownLatch countDownLatch = new CountDownLatch(1);
    countDownLatch.await();
}
 
Example 19
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();
    final AnnotationAction annotationAction = (AnnotationAction) context.getBean("annotationAction");
    String hello = annotationAction.doSayHello("world");
    System.out.println("result: " + hello);
}
 
Example 20
Source Project: dubbo-samples   File: ConsumerBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
    context.start();
    GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
    String hello = greetingServiceConsumer.doSayHello("nacos");
    System.out.println("result: " + hello);
}