use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-security by spring-projects.
the class HttpSecurityBeanDefinitionParser method registerFilterChainProxyIfNecessary.
static void registerFilterChainProxyIfNecessary(ParserContext pc, Object source) {
BeanDefinitionRegistry registry = pc.getRegistry();
if (registry.containsBeanDefinition(BeanIds.FILTER_CHAIN_PROXY)) {
return;
}
// Not already registered, so register the list of filter chains and the
// FilterChainProxy
BeanDefinition listFactoryBean = new RootBeanDefinition(ListFactoryBean.class);
listFactoryBean.getPropertyValues().add("sourceList", new ManagedList());
pc.registerBeanComponent(new BeanComponentDefinition(listFactoryBean, BeanIds.FILTER_CHAINS));
BeanDefinitionBuilder fcpBldr = BeanDefinitionBuilder.rootBeanDefinition(FilterChainProxy.class);
fcpBldr.getRawBeanDefinition().setSource(source);
fcpBldr.addConstructorArgReference(BeanIds.FILTER_CHAINS);
fcpBldr.addPropertyValue("filterChainValidator", new RootBeanDefinition(DefaultFilterChainValidator.class));
BeanDefinition fcpBean = fcpBldr.getBeanDefinition();
pc.registerBeanComponent(new BeanComponentDefinition(fcpBean, BeanIds.FILTER_CHAIN_PROXY));
registry.registerAlias(BeanIds.FILTER_CHAIN_PROXY, BeanIds.SPRING_SECURITY_FILTER_CHAIN);
BeanDefinitionBuilder requestRejected = BeanDefinitionBuilder.rootBeanDefinition(RequestRejectedHandlerPostProcessor.class);
requestRejected.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
requestRejected.addConstructorArgValue("requestRejectedHandler");
requestRejected.addConstructorArgValue(BeanIds.FILTER_CHAIN_PROXY);
requestRejected.addConstructorArgValue("requestRejectedHandler");
AbstractBeanDefinition requestRejectedBean = requestRejected.getBeanDefinition();
String requestRejectedPostProcessorName = pc.getReaderContext().generateBeanName(requestRejectedBean);
registry.registerBeanDefinition(requestRejectedPostProcessorName, requestRejectedBean);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project grails-core by grails.
the class DefaultRuntimeSpringConfiguration method registerBeansWithConfig.
public void registerBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig) {
if (targetSpringConfig == null) {
return;
}
ApplicationContext ctx = targetSpringConfig.getUnrefreshedApplicationContext();
if (ctx instanceof BeanDefinitionRegistry) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx;
registerUnrefreshedBeansWithRegistry(registry);
registerBeansWithRegistry(registry);
}
for (Map.Entry<String, BeanConfiguration> beanEntry : beanConfigs.entrySet()) {
targetSpringConfig.addBeanConfiguration(beanEntry.getKey(), beanEntry.getValue());
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class ConfigurationBeanNameTests method registerOuterConfig_withBeanNameGenerator.
@Test
public void registerOuterConfig_withBeanNameGenerator() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return "custom-" + super.generateBeanName(definition, registry);
}
});
ctx.register(A.class);
ctx.refresh();
assertThat(ctx.containsBean("custom-outer")).isTrue();
assertThat(ctx.containsBean("custom-imported")).isTrue();
assertThat(ctx.containsBean("custom-nested")).isTrue();
assertThat(ctx.containsBean("nestedBean")).isTrue();
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class AnnotationDrivenBeanDefinitionParser method parse.
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Register component for the surrounding <task:annotation-driven> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Nest the concrete post-processor bean in the surrounding component.
BeanDefinitionRegistry registry = parserContext.getRegistry();
String mode = element.getAttribute("mode");
if ("aspectj".equals(mode)) {
// mode="aspectj"
registerAsyncExecutionAspect(element, parserContext);
} else {
// mode="proxy"
if (registry.containsBeanDefinition(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)) {
parserContext.getReaderContext().error("Only one AsyncAnnotationBeanPostProcessor may exist within the context.", source);
} else {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor");
builder.getRawBeanDefinition().setSource(source);
String executor = element.getAttribute("executor");
if (StringUtils.hasText(executor)) {
builder.addPropertyReference("executor", executor);
}
String exceptionHandler = element.getAttribute("exception-handler");
if (StringUtils.hasText(exceptionHandler)) {
builder.addPropertyReference("exceptionHandler", exceptionHandler);
}
if (Boolean.parseBoolean(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) {
builder.addPropertyValue("proxyTargetClass", true);
}
registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
}
}
if (registry.containsBeanDefinition(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
parserContext.getReaderContext().error("Only one ScheduledAnnotationBeanPostProcessor may exist within the context.", source);
} else {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor");
builder.getRawBeanDefinition().setSource(source);
String scheduler = element.getAttribute("scheduler");
if (StringUtils.hasText(scheduler)) {
builder.addPropertyReference("scheduler", scheduler);
}
registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
}
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method setUp.
@BeforeEach
public void setUp() throws Exception {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestApplicationListener.class));
this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions(new ClassPathResource(CONTEXT, getClass()));
}
Aggregations