当前位置: 首页>>代码示例>>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;未经允许,请勿转载。