當前位置: 首頁>>代碼示例>>Java>>正文


Java Config類代碼示例

本文整理匯總了Java中com.ctrip.framework.apollo.Config的典型用法代碼示例。如果您正苦於以下問題:Java Config類的具體用法?Java Config怎麽用?Java Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Config類屬於com.ctrip.framework.apollo包,在下文中一共展示了Config類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processFields

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
private void processFields(Object bean, Field[] declaredFields) {
  for (Field field : declaredFields) {
    ApolloConfig annotation = AnnotationUtils.getAnnotation(field, ApolloConfig.class);
    if (annotation == null) {
      continue;
    }

    Preconditions.checkArgument(Config.class.isAssignableFrom(field.getType()),
        "Invalid type: %s for field: %s, should be Config", field.getType(), field);

    String namespace = annotation.value();
    Config config = ConfigService.getConfig(namespace);

    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, bean, config);
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:ApolloAnnotationProcessor.java

示例2: initializePropertySources

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
protected void initializePropertySources() {
  if (environment.getPropertySources().contains(APOLLO_PROPERTY_SOURCE_NAME)) {
    //already initialized
    return;
  }
  CompositePropertySource composite = new CompositePropertySource(APOLLO_PROPERTY_SOURCE_NAME);

  //sort by order asc
  ImmutableSortedSet<Integer> orders = ImmutableSortedSet.copyOf(NAMESPACE_NAMES.keySet());
  Iterator<Integer> iterator = orders.iterator();

  while (iterator.hasNext()) {
    int order = iterator.next();
    for (String namespace : NAMESPACE_NAMES.get(order)) {
      Config config = ConfigService.getConfig(namespace);

      composite.addPropertySource(new ConfigPropertySource(namespace, config));
    }
  }
  environment.getPropertySources().addFirst(composite);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:22,代碼來源:PropertySourcesProcessor.java

示例3: getConfig

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Override
public Config getConfig(String namespace) {
  Config config = m_configs.get(namespace);

  if (config == null) {
    synchronized (this) {
      config = m_configs.get(namespace);

      if (config == null) {
        ConfigFactory factory = m_factoryManager.getFactory(namespace);

        config = factory.create(namespace);
        m_configs.put(namespace, config);
      }
    }
  }

  return config;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:20,代碼來源:DefaultConfigManager.java

示例4: testMultiplePropertySourcesWithSameProperties

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testMultiplePropertySourcesWithSameProperties() throws Exception {
  int someTimeout = 1000;
  int anotherTimeout = someTimeout + 1;
  int someBatch = 2000;

  Config application = mock(Config.class);
  when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
  when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);

  Config fxApollo = mock(Config.class);
  when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
  mockConfig(FX_APOLLO_NAMESPACE, fxApollo);

  check("spring/XmlConfigPlaceholderTest3.xml", someTimeout, someBatch);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:XmlConfigPlaceholderTest.java

示例5: testMultiplePropertySourcesWithSamePropertiesWithWeight

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception {
  int someTimeout = 1000;
  int anotherTimeout = someTimeout + 1;
  int someBatch = 2000;

  Config application = mock(Config.class);
  when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
  when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);

  Config fxApollo = mock(Config.class);
  when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
  mockConfig(FX_APOLLO_NAMESPACE, fxApollo);

  check("spring/XmlConfigPlaceholderTest4.xml", anotherTimeout, someBatch);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:XmlConfigPlaceholderTest.java

示例6: testMultiplePropertySourcesWithSameProperties

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testMultiplePropertySourcesWithSameProperties() throws Exception {
  int someTimeout = 1000;
  int anotherTimeout = someTimeout + 1;
  int someBatch = 2000;

  Config application = mock(Config.class);
  when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
  when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);

  Config fxApollo = mock(Config.class);
  when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
  mockConfig(FX_APOLLO_NAMESPACE, fxApollo);

  check(someTimeout, someBatch, AppConfig3.class);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:JavaConfigPlaceholderTest.java

示例7: testMultiplePropertySourcesWithSamePropertiesWithWeight

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testMultiplePropertySourcesWithSamePropertiesWithWeight() throws Exception {
  int someTimeout = 1000;
  int anotherTimeout = someTimeout + 1;
  int someBatch = 2000;

  Config application = mock(Config.class);
  when(application.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
  when(application.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));
  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, application);

  Config fxApollo = mock(Config.class);
  when(fxApollo.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(anotherTimeout));
  mockConfig(FX_APOLLO_NAMESPACE, fxApollo);

  check(anotherTimeout, someBatch, AppConfig2.class, AppConfig4.class);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:JavaConfigPlaceholderTest.java

示例8: testApplicationPropertySourceWithValueInjectedAsParameter

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testApplicationPropertySourceWithValueInjectedAsParameter() throws Exception {
  int someTimeout = 1000;
  int someBatch = 2000;

  Config config = mock(Config.class);
  when(config.getProperty(eq(TIMEOUT_PROPERTY), anyString())).thenReturn(String.valueOf(someTimeout));
  when(config.getProperty(eq(BATCH_PROPERTY), anyString())).thenReturn(String.valueOf(someBatch));

  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);

  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig5.class);

  TestJavaConfigBean2 bean = context.getBean(TestJavaConfigBean2.class);

  assertEquals(someTimeout, bean.getTimeout());
  assertEquals(someBatch, bean.getBatch());
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:19,代碼來源:JavaConfigPlaceholderTest.java

示例9: testGetConfigWithLocalFileAndWithRemoteConfig

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception {
  String someKey = "someKey";
  String someValue = "someValue";
  String anotherValue = "anotherValue";
  Properties properties = new Properties();
  properties.put(someKey, someValue);
  createLocalCachePropertyFile(properties);

  ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue));
  ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
  startServerWithHandlers(handler);

  Config config = ConfigService.getAppConfig();

  assertEquals(anotherValue, config.getProperty(someKey, null));
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:ConfigIntegrationTest.java

示例10: testCreate

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testCreate() throws Exception {
  String someNamespace = "someName";
  Properties someProperties = new Properties();
  String someKey = "someKey";
  String someValue = "someValue";
  someProperties.setProperty(someKey, someValue);

  LocalFileConfigRepository someLocalConfigRepo = mock(LocalFileConfigRepository.class);
  when(someLocalConfigRepo.getConfig()).thenReturn(someProperties);

  doReturn(someLocalConfigRepo).when(defaultConfigFactory).createLocalConfigRepository(someNamespace);

  Config result = defaultConfigFactory.create(someNamespace);

  assertThat("DefaultConfigFactory should create DefaultConfig", result,
      is(instanceOf(DefaultConfig.class)));
  assertEquals(someValue, result.getProperty(someKey, null));
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:20,代碼來源:DefaultConfigFactoryTest.java

示例11: processMethods

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
private void processMethods(final Object bean, Method[] declaredMethods) {
  for (final Method method : declaredMethods) {
    ApolloConfigChangeListener annotation = AnnotationUtils.findAnnotation(method, ApolloConfigChangeListener.class);
    if (annotation == null) {
      continue;
    }

    Class<?>[] parameterTypes = method.getParameterTypes();
    Preconditions.checkArgument(parameterTypes.length == 1,
        "Invalid number of parameters: %s for method: %s, should be 1", parameterTypes.length, method);
    Preconditions.checkArgument(ConfigChangeEvent.class.isAssignableFrom(parameterTypes[0]),
        "Invalid parameter type: %s for method: %s, should be ConfigChangeEvent", parameterTypes[0], method);

    ReflectionUtils.makeAccessible(method);
    String[] namespaces = annotation.value();
    for (String namespace : namespaces) {
      Config config = ConfigService.getConfig(namespace);

      config.addChangeListener(new ConfigChangeListener() {
        @Override
        public void onChange(ConfigChangeEvent changeEvent) {
          ReflectionUtils.invokeMethod(method, bean, changeEvent);
        }
      });
    }
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:28,代碼來源:ApolloAnnotationProcessor.java

示例12: testApolloConfig

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test
public void testApolloConfig() throws Exception {
  Config applicationConfig = mock(Config.class);
  Config fxApolloConfig = mock(Config.class);

  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig);
  mockConfig(FX_APOLLO_NAMESPACE, fxApolloConfig);

  TestApolloConfigBean1 bean = getBean("spring/XmlConfigAnnotationTest1.xml", TestApolloConfigBean1.class);

  assertEquals(applicationConfig, bean.getConfig());
  assertEquals(applicationConfig, bean.getAnotherConfig());
  assertEquals(fxApolloConfig, bean.getYetAnotherConfig());
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:15,代碼來源:XMLConfigAnnotationTest.java

示例13: testApolloConfigWithWrongFieldType

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test(expected = BeanCreationException.class)
public void testApolloConfigWithWrongFieldType() throws Exception {
  Config applicationConfig = mock(Config.class);

  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig);

  getBean("spring/XmlConfigAnnotationTest2.xml", TestApolloConfigBean2.class);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:9,代碼來源:XMLConfigAnnotationTest.java

示例14: testApolloConfigChangeListenerWithWrongParamType

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test(expected = BeanCreationException.class)
public void testApolloConfigChangeListenerWithWrongParamType() throws Exception {
  Config applicationConfig = mock(Config.class);

  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig);

  getBean("spring/XmlConfigAnnotationTest4.xml", TestApolloConfigChangeListenerBean2.class);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:9,代碼來源:XMLConfigAnnotationTest.java

示例15: testApolloConfigChangeListenerWithWrongParamCount

import com.ctrip.framework.apollo.Config; //導入依賴的package包/類
@Test(expected = BeanCreationException.class)
public void testApolloConfigChangeListenerWithWrongParamCount() throws Exception {
  Config applicationConfig = mock(Config.class);

  mockConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationConfig);

  getBean("spring/XmlConfigAnnotationTest5.xml", TestApolloConfigChangeListenerBean3.class);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:9,代碼來源:XMLConfigAnnotationTest.java


注:本文中的com.ctrip.framework.apollo.Config類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。