Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grails-doc/src/en/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gettingStarted:
upgrading:
title: Upgrading from the previous versions
upgrading80x: Upgrading from Grails 7 to Grails 8
beanRegistryAdapter: BeanBuilder to BeanRegistry strategy
upgrading72x: Upgrading from Grails 7.1 to Grails 7.2
upgrading71x: Upgrading from Grails 7.0 to Grails 7.1
upgrading70x: Upgrading from Grails 6 to Grails 7.0
Expand Down
7 changes: 7 additions & 0 deletions grails-doc/src/en/guide/upgrading/beanRegistryAdapter.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== BeanBuilder to BeanRegistry strategy

Grails 8.1 introduces an experimental `grails.spring.BeanRegistryAdapter` seam as the first step toward the Spring 7 `BeanRegistrar` direction tracked in issue #15824.
The initial `BeanBuilderBeanRegistryAdapter` delegates to the existing `BeanBuilder`, so `resources.groovy`, plugin `doWithSpring`, and existing BeanBuilder APIs continue to work unchanged.

The intended migration path is to move call sites behind the adapter first, then add a Spring 7 BeanRegistrar-backed implementation once the framework integration points are ready.
BeanBuilder is not removed or behaviorally changed by this seed.
Comment thread
jamesfredley marked this conversation as resolved.
3 changes: 2 additions & 1 deletion grails-spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ dependencies {

apply {
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
}
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package grails.spring;

import java.util.Map;

import groovy.lang.Closure;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

/**
* BeanRegistryAdapter backed by the existing BeanBuilder implementation.
*
* @since 8.1
*/
public class BeanBuilderBeanRegistryAdapter implements BeanRegistryAdapter {

private final BeanBuilder beanBuilder;

public BeanBuilderBeanRegistryAdapter() {
this(new BeanBuilder());
}

public BeanBuilderBeanRegistryAdapter(BeanBuilder beanBuilder) {
this.beanBuilder = beanBuilder;
}
Comment thread
jamesfredley marked this conversation as resolved.
Outdated

public BeanBuilder getBeanBuilder() {
return beanBuilder;
}

@Override
public BeanRegistryAdapter beans(Closure<?> closure) {
beanBuilder.beans(closure);
return this;
}

@Override
public Map<String, BeanDefinition> getBeanDefinitions() {
return beanBuilder.getBeanDefinitions();
}

@Override
public void registerBeans(BeanDefinitionRegistry registry) {
beanBuilder.registerBeans(registry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package grails.spring;

import java.util.Map;

import groovy.lang.Closure;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

/**
* Experimental adapter seam for the BeanBuilder to Spring BeanRegistrar transition.
*
* @since 8.1
*/
public interface BeanRegistryAdapter {
Comment thread
jamesfredley marked this conversation as resolved.
Outdated

BeanRegistryAdapter beans(Closure<?> closure);

Map<String, BeanDefinition> getBeanDefinitions();

void registerBeans(BeanDefinitionRegistry registry);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package grails.spring

import org.junit.jupiter.api.Test

import org.springframework.context.support.GenericApplicationContext

import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.jupiter.api.Assertions.assertTrue

class BeanBuilderBeanRegistryAdapterTest {

@Test
void adapterRegistersBeansThroughExistingBeanBuilderPath() {
BeanRegistryAdapter adapter = new BeanBuilderBeanRegistryAdapter()
GenericApplicationContext applicationContext = new GenericApplicationContext()
try {
adapter.beans {
sampleBean(String, 'adapter')
}
adapter.registerBeans(applicationContext)
applicationContext.refresh()

assertTrue(adapter.beanDefinitions.containsKey('sampleBean'))
assertEquals('adapter', applicationContext.getBean('sampleBean'))
}
finally {
applicationContext.close()
}
}
}
Loading