Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert CoreConfiguration to CoreAutoConfiguration #13876

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
api "org.springframework:spring-tx"
api "org.springframework:spring-beans"
api "org.springframework:spring-context"
api "org.springframework.boot:spring-boot-autoconfigure"

compileOnly "org.springframework:spring-test"
compileOnly "org.apache.groovy:groovy-templates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.grails.spring.DefaultRuntimeSpringConfiguration
import org.grails.spring.RuntimeSpringConfiguration
import org.grails.spring.aop.autoproxy.GroovyAwareAspectJAwareAdvisorAutoProxyCreator
import org.grails.spring.aop.autoproxy.GroovyAwareInfrastructureAdvisorAutoProxyCreator
import org.grails.spring.context.support.GrailsPlaceholderConfigurer
import org.grails.spring.context.support.MapBasedSmartPropertyOverrideConfigurer
import org.grails.spring.RuntimeSpringConfigUtilities
import org.grails.core.io.DefaultResourceLocator
Expand Down Expand Up @@ -66,17 +65,12 @@ class CoreGrailsPlugin extends Plugin {

// Grails config as properties
def config = application.config
def placeHolderPrefix = config.getProperty(Settings.SPRING_PLACEHOLDER_PREFIX, '${')


// enable post-processing of @Configuration beans defined by plugins
grailsConfigurationClassPostProcessor ConfigurationClassPostProcessor
grailsBeanOverrideConfigurer(MapBasedSmartPropertyOverrideConfigurer) {
delegate.grailsApplication = application
}
propertySourcesPlaceholderConfigurer(GrailsPlaceholderConfigurer) {
placeholderPrefix = placeHolderPrefix
}

Class proxyCreatorClazz = null
// replace AutoProxy advisor with Groovy aware one
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2004-2019 the original author or authors.
*
* Licensed 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
*
* http://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 org.grails.plugins.core;

import grails.config.ConfigProperties;
import grails.config.Settings;
import grails.core.GrailsApplication;
import org.grails.spring.context.support.GrailsPlaceholderConfigurer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered;

/**
* Core beans.
*
* @author graemerocher
* @since 4.0
*/
@AutoConfiguration(before = { PropertyPlaceholderAutoConfiguration.class })
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
public class CoreAutoConfiguration {

@Value("${" + Settings.SPRING_PLACEHOLDER_PREFIX + ":#{null}}")
private String placeholderPrefix;

@Bean
@Primary
public ClassLoader classLoader(GrailsApplication grailsApplication) {
return grailsApplication.getClassLoader();
}

@Bean
@Primary
public ConfigProperties grailsConfigProperties(GrailsApplication grailsApplication) {
return new ConfigProperties(grailsApplication.getConfig());
}

@Bean
@Primary
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
GrailsPlaceholderConfigurer grailsPlaceholderConfigurer = new GrailsPlaceholderConfigurer();
if (placeholderPrefix != null) {
grailsPlaceholderConfigurer.setPlaceholderPrefix(placeholderPrefix);
}
return grailsPlaceholderConfigurer;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.grails.plugins.core.CoreConfiguration
org.grails.plugins.core.CoreAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grails.spring

import grails.core.DefaultGrailsApplication
import org.grails.plugins.CoreGrailsPlugin
import org.grails.spring.context.support.GrailsPlaceholderConfigurer
import spock.lang.Issue
import spock.lang.Specification

Expand Down Expand Up @@ -29,6 +30,7 @@ class GrailsPlaceHolderConfigurerCorePluginRuntimeSpec extends Specification{
plugin.grailsApplication = app
bb.beans plugin.doWithSpring()
bb.beans {
propertySourcesPlaceholderConfigurer(GrailsPlaceholderConfigurer)
testBean(ReplacePropertyBean) {
foo = '${foo.bar}'
}
Expand Down
2 changes: 0 additions & 2 deletions grails-web-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dependencies {
compileOnly "jakarta.servlet:jakarta.servlet-api"
testCompileOnly "org.springframework:spring-test"

// now used by plugins for autoconfiguration
api "org.springframework.boot:spring-boot-autoconfigure"
api "org.springframework:spring-webmvc"
api "org.springframework:spring-context-support"
implementation "com.github.ben-manes.caffeine:caffeine"
Expand Down
Loading