Java Code Examples for org.springframework.context.support.GenericApplicationContext#getBeanFactory()

The following examples show how to use org.springframework.context.support.GenericApplicationContext#getBeanFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	@SuppressWarnings("resource")
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Method method = ReflectionUtils.findMethod(getClass(), "handleMessage", (Class<?>[]) null);
	this.paramRequired = new SynthesizingMethodParameter(method, 0);
	this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
	this.paramSystemPropertyDefaultValue = new SynthesizingMethodParameter(method, 2);
	this.paramSystemPropertyName = new SynthesizingMethodParameter(method, 3);
	this.paramNotAnnotated = new SynthesizingMethodParameter(method, 4);
	this.paramOptional = new SynthesizingMethodParameter(method, 5);
	this.paramNativeHeader = new SynthesizingMethodParameter(method, 6);

	this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
 
Example 2
Source File: HeaderMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	@SuppressWarnings("resource")
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Method method = getClass().getDeclaredMethod("handleMessage",
			String.class, String.class, String.class, String.class, String.class);
	this.paramRequired = new SynthesizingMethodParameter(method, 0);
	this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
	this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
	this.paramNotAnnotated = new SynthesizingMethodParameter(method, 3);
	this.paramNativeHeader = new SynthesizingMethodParameter(method, 4);

	this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
 
Example 3
Source File: WebContextTestExecutionListener.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {

    if (testContext.getApplicationContext() instanceof GenericApplicationContext) {
        GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext();
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Scope requestScope = new SimpleThreadScope();
        beanFactory.registerScope("request", requestScope);
        Scope sessionScope = new SimpleThreadScope();
        beanFactory.registerScope("session", sessionScope);
    }
}
 
Example 4
Source File: JeeNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	GenericApplicationContext ctx = new GenericApplicationContext();
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(
			new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
	ctx.refresh();
	this.beanFactory = ctx.getBeanFactory();
	this.beanFactory.getBeanNamesForType(ITestBean.class);
}
 
Example 5
Source File: HeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveOptionalHeaderWithValue() throws Exception {
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();

	HeaderMethodArgumentResolver resolver =
			new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Message<String> message = MessageBuilder.withPayload("foo").setHeader("foo", "bar").build();
	Object result = resolver.resolveArgument(paramOptional, message);
	assertEquals(Optional.of("bar"), result);
}
 
Example 6
Source File: HeaderMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveOptionalHeaderAsEmpty() throws Exception {
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();

	HeaderMethodArgumentResolver resolver =
			new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Message<String> message = MessageBuilder.withPayload("foo").build();
	Object result = resolver.resolveArgument(paramOptional, message);
	assertEquals(Optional.empty(), result);
}
 
Example 7
Source File: JeeNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	GenericApplicationContext ctx = new GenericApplicationContext();
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(
			new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
	ctx.refresh();
	this.beanFactory = ctx.getBeanFactory();
	this.beanFactory.getBeanNamesForType(ITestBean.class);
}
 
Example 8
Source File: JeeNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	GenericApplicationContext ctx = new GenericApplicationContext();
	new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(
			new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
	ctx.refresh();
	this.beanFactory = ctx.getBeanFactory();
	this.beanFactory.getBeanNamesForType(ITestBean.class);
}
 
Example 9
Source File: LensBootstrap.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public LensJLineShellComponent getLensJLineShellComponent() {
  GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext();
  RootBeanDefinition rbd = new RootBeanDefinition();
  rbd.setBeanClass(LensJLineShellComponent.class);
  DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
  bf.registerBeanDefinition(LensJLineShellComponent.class.getSimpleName(), rbd);
  return ctx.getBean(LensJLineShellComponent.class);
}
 
Example 10
Source File: HeaderMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Before
public void setup() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), context.getBeanFactory());
}
 
Example 11
Source File: HeaderMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Before
public void setup() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), context.getBeanFactory());
}