下面列出了org.springframework.context.annotation.AnnotationConfigApplicationContext#start ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
private static void addPostprocessorAndUpdateContext(Class<?> currentVerticleClass,
AnnotationConfigApplicationContext annotationConfigApplicationContext) {
annotationConfigApplicationContext.addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass));
annotationConfigApplicationContext.refresh();
annotationConfigApplicationContext.start();
annotationConfigApplicationContext.registerShutdownHook();
}
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();
}
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();
}
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();
}
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();
}
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);
}
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();
}
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!");
}
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();
}
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);
}
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();
}
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();
}
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");
}
@Test
public void shouldCloseTaskExecutor() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
context.start();
context.close();
assertThat(context.isActive()).isFalse();
}
@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();
}
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);
}
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();
}
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);
}
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);
}