Search in sources :

Example 36 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createRememberMeProvider.

private void createRememberMeProvider(String key) {
    RootBeanDefinition provider = new RootBeanDefinition(RememberMeAuthenticationProvider.class);
    provider.setSource(rememberMeFilter.getSource());
    provider.getConstructorArgumentValues().addGenericArgumentValue(key);
    String id = pc.getReaderContext().generateBeanName(provider);
    pc.registerBeanComponent(new BeanComponentDefinition(provider, id));
    rememberMeProviderRef = new RuntimeBeanReference(id);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 37 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-security by spring-projects.

the class GrantedAuthorityDefaultsParserUtils method registerWithDefaultRolePrefix.

static RootBeanDefinition registerWithDefaultRolePrefix(ParserContext pc, Class<? extends AbstractGrantedAuthorityDefaultsBeanFactory> beanFactoryClass) {
    RootBeanDefinition beanFactoryDefinition = new RootBeanDefinition(beanFactoryClass);
    String beanFactoryRef = pc.getReaderContext().generateBeanName(beanFactoryDefinition);
    pc.getRegistry().registerBeanDefinition(beanFactoryRef, beanFactoryDefinition);
    RootBeanDefinition bean = new RootBeanDefinition();
    bean.setFactoryBeanName(beanFactoryRef);
    bean.setFactoryMethodName("getBean");
    return bean;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition)

Example 38 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-boot by spring-projects.

the class ServletComponentScanRegistrarTests method packagesConfiguredWithValueAsm.

@Test
public void packagesConfiguredWithValueAsm() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.registerBeanDefinition("valuePackages", new RootBeanDefinition(ValuePackages.class.getName()));
    this.context.refresh();
    ServletComponentRegisteringPostProcessor postProcessor = this.context.getBean(ServletComponentRegisteringPostProcessor.class);
    assertThat(postProcessor.getPackagesToScan()).contains("com.example.foo", "com.example.bar");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 39 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method beanDefinition.

private BeanDefinition beanDefinition(Object bean) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(getClass());
    beanDefinition.setFactoryMethodName("getBean");
    ConstructorArgumentValues constructorArguments = new ConstructorArgumentValues();
    constructorArguments.addGenericArgumentValue(bean);
    beanDefinition.setConstructorArgumentValues(constructorArguments);
    return beanDefinition;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 40 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.

the class AnnotationAsyncExecutionAspectTests method qualifiedAsyncMethodsAreRoutedToCorrectExecutor.

/*
	@Test
	public void methodReturningNonVoidNonFutureInAsyncClassGetsRoutedSynchronously() {
		ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
		int returnValue = obj.return5();
		assertEquals(5, returnValue);
		assertEquals(0, executor.submitStartCounter);
		assertEquals(0, executor.submitCompleteCounter);
	}
	*/
@Test
public void qualifiedAsyncMethodsAreRoutedToCorrectExecutor() throws InterruptedException, ExecutionException {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
    AnnotationAsyncExecutionAspect.aspectOf().setBeanFactory(beanFactory);
    ClassWithQualifiedAsyncMethods obj = new ClassWithQualifiedAsyncMethods();
    Future<Thread> defaultThread = obj.defaultWork();
    assertThat(defaultThread.get(), not(Thread.currentThread()));
    assertThat(defaultThread.get().getName(), not(startsWith("e1-")));
    ListenableFuture<Thread> e1Thread = obj.e1Work();
    assertThat(e1Thread.get().getName(), startsWith("e1-"));
    CompletableFuture<Thread> e1OtherThread = obj.e1OtherWork();
    assertThat(e1OtherThread.get().getName(), startsWith("e1-"));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test)

Aggregations

RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)704 Test (org.junit.Test)522 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)311 TestBean (org.springframework.tests.sample.beans.TestBean)159 ITestBean (org.springframework.tests.sample.beans.ITestBean)143 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)133 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)85 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)80 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)77 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)77 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 Element (org.w3c.dom.Element)47 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)46 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)36 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)31 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)30 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)30 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)28 Properties (java.util.Properties)26 ManagedList (org.springframework.beans.factory.support.ManagedList)25