org.springframework.context.ApplicationContext.isSingleton()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.springframework.context.ApplicationContext.isSingleton()方法的一些代码示例,展示了ApplicationContext.isSingleton()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.isSingleton()方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:isSingleton

ApplicationContext.isSingleton介绍

暂无

代码示例

代码示例来源:origin: shuzheng/zheng

/**
 * 是否是单例
 * @param beanName
 * @return
 */
public static boolean isSingleton(String beanName) {
  return context.isSingleton(beanName);
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

public static boolean isSingleton(String name) {
  return applicationContext.isSingleton(name);
}

代码示例来源:origin: geoserver/geoserver

private static Object getBean(ApplicationContext context, String name) {
  Object bean = singletonBeanCache.get(name);
  if (bean == null && context != null) {
    bean = context.getBean(name);
    if (bean != null && context.isSingleton(name)) {
      singletonBeanCache.put(name, bean);
    }
  }
  return bean;
}

代码示例来源:origin: spring-projects/spring-framework

String handlerName = (String) handler;
ApplicationContext applicationContext = obtainApplicationContext();
if (applicationContext.isSingleton(handlerName)) {
  resolvedHandler = applicationContext.getBean(handlerName);

代码示例来源:origin: spring-projects/spring-framework

if (obtainApplicationContext().isSingleton(handlerName)) {
  resolvedHandler = obtainApplicationContext().getBean(handlerName);

代码示例来源:origin: org.springframework/spring-webmvc

String handlerName = (String) handler;
ApplicationContext applicationContext = obtainApplicationContext();
if (applicationContext.isSingleton(handlerName)) {
  resolvedHandler = applicationContext.getBean(handlerName);

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPrototype() {
  ApplicationContext context = createContext(ScopedProxyMode.NO);
  ScopedTestBean bean = (ScopedTestBean) context.getBean("prototype");
  assertNotNull(bean);
  assertTrue(context.isPrototype("prototype"));
  assertFalse(context.isSingleton("prototype"));
}

代码示例来源:origin: geoserver/geoserver

@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testExtensionProvider() {
  ApplicationContext appContext = createMock(ApplicationContext.class);
  GeoServerExtensions gse = new GeoServerExtensions();
  gse.setApplicationContext(appContext);
  expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]);
  expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class))
      .andReturn(new String[0]);
  expect(appContext.getBeanNamesForType(ExtensionProvider.class))
      .andReturn(new String[] {"testKey2"});
  ExtensionProvider xp = createMock(ExtensionProvider.class);
  expect(xp.getExtensionPoint()).andReturn(GeoServerExtensionsTest.class);
  expect(xp.getExtensions(GeoServerExtensionsTest.class)).andReturn(Arrays.asList(this));
  expect(appContext.getBean("testKey2")).andReturn(xp);
  expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
  replay(xp);
  replay(appContext);
  assertEquals(1, GeoServerExtensions.extensions(GeoServerExtensionsTest.class).size());
  verify(xp);
  verify(appContext);
}

代码示例来源:origin: geoserver/geoserver

.andReturn(new String[0]);
expect(customAppContext.getBean("itDoesntMatterForThePurpose")).andReturn(this);
expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
expect(customAppContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
replay(customAppContext);
replay(appContext);

代码示例来源:origin: geoserver/geoserver

.anyTimes();
EasyMock.expect(appContext.getBean("geoServerLoader")).andReturn(loader).anyTimes();
EasyMock.expect(appContext.isSingleton("geoServerLoader")).andReturn(true).anyTimes();

代码示例来源:origin: geoserver/geoserver

@Test
public void testBeanString() {
  ApplicationContext appContext = createMock(ApplicationContext.class);
  GeoServerExtensions gse = new GeoServerExtensions();
  gse.setApplicationContext(null);
  Logger LOGGER = Logging.getLogger("org.geoserver.platform");
  Level level = LOGGER.getLevel();
  try {
    LOGGER.setLevel(Level.SEVERE);
    assertNull(GeoServerExtensions.bean("beanName"));
  } finally {
    LOGGER.setLevel(level);
  }
  gse.setApplicationContext(appContext);
  expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
  expect(appContext.getBean("beanName")).andReturn(null); // call #1
  expect(appContext.getBean("beanName")).andReturn(this); // call #2
  replay(appContext);
  assertNull(GeoServerExtensions.bean("beanName")); // call #1
  assertSame(this, GeoServerExtensions.bean("beanName")); // call #2
  verify(appContext);
}

代码示例来源:origin: geoserver/geoserver

.anyTimes();
EasyMock.expect(appContext.getBean("geoServerLoader")).andReturn(loader).anyTimes();
EasyMock.expect(appContext.isSingleton("geoServerLoader")).andReturn(true).anyTimes();

代码示例来源:origin: geoserver/geoserver

@Test
public void testExtensions() {
  ApplicationContext appContext = createMock(ApplicationContext.class);
  GeoServerExtensions gse = new GeoServerExtensions();
  gse.setApplicationContext(appContext);
  assertEquals(0, GeoServerExtensions.extensionsCache.size());
  expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]);
  expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class))
      .andReturn(new String[] {"testKey", "fakeKey"});
  expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]);
  expect(appContext.getBean("testKey")).andReturn(this);
  // note I'm testing null is a valid value. If that's not the case, it
  // should be reflected in the code, but I'm writing the test after the
  // code so that's what it does
  expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
  expect(appContext.getBean("fakeKey")).andReturn(null);
  replay(appContext);
  List<GeoServerExtensionsTest> extensions =
      GeoServerExtensions.extensions(GeoServerExtensionsTest.class);
  assertNotNull(extensions);
  assertEquals(2, extensions.size());
  assertTrue(extensions.contains(this));
  assertTrue(extensions.contains(null));
  assertEquals(3, GeoServerExtensions.extensionsCache.size());
  assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class));
  assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class));
  assertEquals(
      2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length);
  verify(appContext);
}

代码示例来源:origin: geoserver/geoserver

expect(appContext.getBeanNamesForType(ModuleStatus.class))
    .andStubReturn(new String[] {"testStatus", "defaultStatus"});
expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes();
expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]);
EasyMock.replay(status, appContext);

代码示例来源:origin: timebusker/spring-boot

public static boolean isSingleton(String name) {
  return applicationContext.isSingleton(name);
}

代码示例来源:origin: mulesoft/mule

@Override
public boolean isSingleton(String key) {
 return applicationContext.isSingleton(key);
}

代码示例来源:origin: Nepxion/Discovery

public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
  return applicationContext.isSingleton(name);
}

代码示例来源:origin: FlowCI/flow-platform

public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
  return applicationContext.isSingleton(name);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testSingletonScopeWithNoProxy() {
  RequestContextHolder.setRequestAttributes(oldRequestAttributes);
  ApplicationContext context = createContext(ScopedProxyMode.NO);
  ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
  assertTrue(context.isSingleton("singleton"));
  assertFalse(context.isPrototype("singleton"));
  // should not be a proxy
  assertFalse(AopUtils.isAopProxy(bean));
  assertEquals(DEFAULT_NAME, bean.getName());
  bean.setName(MODIFIED_NAME);
  RequestContextHolder.setRequestAttributes(newRequestAttributes);
  // not a proxy so this should not have changed
  assertEquals(MODIFIED_NAME, bean.getName());
  // singleton bean, so name should be modified even after lookup
  ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
  assertEquals(MODIFIED_NAME, bean2.getName());
}

代码示例来源:origin: mulesoft/mule

public Map<String, Object> getDependencies(String key) {
 if (!readOnly) {
  Map<String, Object> dependents = new HashMap<>();
  for (String dependentKey : ((ConfigurableApplicationContext) applicationContext).getBeanFactory()
    .getDependenciesForBean(key)) {
   boolean isBeanDefinition =
     ((ConfigurableApplicationContext) applicationContext).getBeanFactory().containsBeanDefinition(dependentKey);
   if (isBeanDefinition && applicationContext.isSingleton(dependentKey)) {
    dependents.put(dependentKey, get(dependentKey));
   }
  }
  return dependents;
 }
 throw new UnsupportedOperationException("This operation is only available when this registry is backed by a ConfigurableApplicationContext");
}

相关文章