本文整理了Java中org.springframework.context.support.ClassPathXmlApplicationContext.getBeanFactory()
方法的一些代码示例,展示了ClassPathXmlApplicationContext.getBeanFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassPathXmlApplicationContext.getBeanFactory()
方法的具体详情如下:
包路径:org.springframework.context.support.ClassPathXmlApplicationContext
类名称:ClassPathXmlApplicationContext
方法名:getBeanFactory
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFactoryBeanAndApplicationListener() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD);
ctx.getBeanFactory().registerSingleton("manualFBAAL", new FactoryBeanAndApplicationListener());
assertEquals(2, ctx.getBeansOfType(ApplicationListener.class).size());
ctx.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInlineScriptFromTag() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
BeanDefinition bd = ctx.getBeanFactory().getBeanDefinition("calculator");
assertTrue(ObjectUtils.containsElement(bd.getDependsOn(), "messenger"));
Calculator calculator = (Calculator) ctx.getBean("calculator");
assertNotNull(calculator);
assertFalse(calculator instanceof Refreshable);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCustomScopeMetadataResolver() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customScopeResolverTests.xml");
BeanDefinition bd = context.getBeanFactory().getBeanDefinition("fooServiceImpl");
assertEquals("myCustomScope", bd.getScope());
assertFalse(bd.isSingleton());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void invokeOnLazyInitBean() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/lazyInit.xml");
assertFalse(ctx.getBeanFactory().containsSingleton("testBean"));
assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
try {
MBeanServer server = (MBeanServer) ctx.getBean("server");
ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean2");
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "foo", name);
}
finally {
ctx.close();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testDefaultScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyDefaultTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
context.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testNoScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyNoTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
context.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testTargetClassScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInterfacesScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
// should cast to the interface
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertTrue(AopUtils.isJdkDynamicProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testUserSpecifiedTaskExecutor() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/user-specified-split-task-executor-context.xml");
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) context.getBeanFactory();
PropertyValue propertyValue = new JsrSplitParser(null).getSplitTaskExecutorPropertyValue(registry);
RuntimeBeanReference runtimeBeanReferenceValue = (RuntimeBeanReference) propertyValue.getValue();
Assert.assertTrue("RuntimeBeanReference should have a name of jsr352splitTaskExecutor" , "jsr352splitTaskExecutor".equals(runtimeBeanReferenceValue.getBeanName()));
context.close();
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDefaultTaskExecutor() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/default-split-task-executor-context.xml");
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) context.getBeanFactory();
PropertyValue propertyValue = new JsrSplitParser(null).getSplitTaskExecutorPropertyValue(registry);
Assert.assertTrue("Task executor not an instance of SimpleAsyncTaskExecutor" , (propertyValue.getValue() instanceof SimpleAsyncTaskExecutor));
context.close();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testVanillaConfiguration() throws Exception {
assertTrue(context.getBeanFactory().containsBeanDefinition("vanilla"));
context.getBean("vanilla");
}
代码示例来源:origin: org.dspace/dspace-services-impl
/**
* @return the current spring bean factory OR null if there is not one
*/
public ListableBeanFactory getBeanFactory() {
if (applicationContext != null) {
return applicationContext.getBeanFactory();
}
return null;
}
代码示例来源:origin: DSpace/DSpace
/**
* @return the current spring bean factory OR null if there is not one
*/
public ListableBeanFactory getBeanFactory() {
if (applicationContext != null) {
return applicationContext.getBeanFactory();
}
return null;
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testExpressionBasedConfiguration() throws Exception {
assertTrue(context.getBeanFactory().containsBeanDefinition("expression"));
Object target = context.getBean("expression");
assertNotNull(ReflectionTestUtils.getField(ReflectionTestUtils.getField(target, "handler"),
"routingKeyGenerator"));
}
代码示例来源:origin: org.dspace/dspace-services-impl
public List<String> getServicesNames() {
ArrayList<String> beanNames = new ArrayList<String>();
String[] singletons = applicationContext.getBeanFactory().getSingletonNames();
for (String singleton : singletons) {
if (singleton.startsWith("org.springframework.context")) {
continue; // skip the spring standard ones
}
beanNames.add(singleton);
}
Collections.sort(beanNames);
return beanNames;
}
代码示例来源:origin: DSpace/DSpace
@Override
public List<String> getServicesNames() {
ArrayList<String> beanNames = new ArrayList<String>();
String[] singletons = applicationContext.getBeanFactory().getSingletonNames();
for (String singleton : singletons) {
if (singleton.startsWith("org.springframework.context")) {
continue; // skip the spring standard ones
}
beanNames.add(singleton);
}
Collections.sort(beanNames);
return beanNames;
}
代码示例来源:origin: org.mule.modules/mule-spring-module
@Override
public <T> Map<String, T> getObjectsByType(Class<T> type) {
if (isSpringInternalType(type)) {
return emptyMap();
}
Map<String, T> beans = applicationContext.getBeansOfType(type);
return beans.entrySet().stream().filter(entry -> applicationContext.getBeanFactory().containsBeanDefinition(entry.getKey()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
代码示例来源:origin: org.dspace/dspace-services-impl
public void registerService(String name, Object service) {
if (name == null || service == null) {
throw new IllegalArgumentException("name and service must not be null for service registration");
}
try {
applicationContext.getBeanFactory().autowireBean(service);
} catch (BeansException e) {
throw new IllegalArgumentException("Invalid service ("+service+") with name ("+name+") registration: " + e.getMessage(), e);
}
registerBean(name, service);
}
代码示例来源:origin: DSpace/DSpace
@Override
public void registerService(String name, Object service) {
if (name == null || service == null) {
throw new IllegalArgumentException("name and service must not be null for service registration");
}
try {
applicationContext.getBeanFactory().autowireBean(service);
} catch (BeansException e) {
throw new IllegalArgumentException(
"Invalid service (" + service + ") with name (" + name + ") registration: " + e.getMessage(), e);
}
registerBean(name, service);
}
代码示例来源:origin: it.tidalwave.northernwind/it-tidalwave-northernwind-core-default
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Test
public void must_use_no_context_path_when_ServletContext_is_not_available()
throws Exception
{
((DefaultListableBeanFactory)context.getBeanFactory()).removeBeanDefinition("servletContext");
underTest = context.getBean(DefaultSiteProvider.class);
assertThat(underTest.getContextPath(), is("/"));
}
内容来源于网络,如有侵权,请联系作者删除!