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

The following examples show how to use org.springframework.context.annotation.AnnotationConfigApplicationContext#start() . 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
Source File: ApplicationBootstrap.java    From j360-dubbo-app-all with Apache License 2.0 6 votes vote down vote up
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
Source File: MetadataLocalAnnotationConsumer.java    From dubbo-samples with 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();

    printServiceData();

    AnnotationAction annotationAction = context.getBean("annotationAction", AnnotationAction.class);
    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
}
 
Example 3
Source File: ConsumerBootstrap.java    From dubbo-samples with 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);
}
 
Example 4
Source File: AnnotationConsumer.java    From dubbo-samples with 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);
}
 
Example 5
Source File: ApplicationBootstrap.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
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 6
Source File: AnnotationConsumer.java    From dubbo-samples with 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);
}
 
Example 7
Source File: MetadataCollectorTest.java    From chassis with 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 8
Source File: AopCleanupTest.java    From ShedLock with 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 9
Source File: AnnotationProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
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 10
Source File: MetadataConfigcenterProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
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 11
Source File: JavaConfigContainer.java    From dubbox with 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 12
Source File: SpringVerticleFactory.java    From spring-vertx-ext with Apache License 2.0 5 votes vote down vote up
private static void addPostprocessorAndUpdateContext(Class<?> currentVerticleClass,
    AnnotationConfigApplicationContext annotationConfigApplicationContext) {
    annotationConfigApplicationContext.addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass));
    annotationConfigApplicationContext.refresh();
    annotationConfigApplicationContext.start();
    annotationConfigApplicationContext.registerShutdownHook();
}
 
Example 13
Source File: SimpleRegistryAnnotationProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
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 14
Source File: Resilience4jAnnotationConsumer.java    From dubbo-samples with 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();

        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 15
Source File: Resilience4jAnnotationProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
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 16
Source File: SimpleRegistryAnnotationConsumer.java    From dubbo-samples with 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();

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

    String hello = annotationAction.doSayHello("world");
    System.out.println("result :" + hello);
}
 
Example 17
Source File: JavaConfigContainer.java    From dubbox with 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 18
Source File: ProviderBootstrap.java    From dubbo-samples with 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 19
Source File: JavaConfigContainer.java    From dubbox with 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 20
Source File: AnnotationConsumer.java    From dubbo-2.6.5 with 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();
}