Skip to content

Commit

Permalink
Make grailsResourceLocator Bean Auto-Configure
Browse files Browse the repository at this point in the history
Closes gh-605
  • Loading branch information
rainboyan committed Sep 27, 2024
1 parent 63014ef commit 36df0c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2023 the original author or authors.
* Copyright 2004-2024 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.
Expand All @@ -15,15 +15,21 @@
*/
package org.grails.plugins.core;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;

import grails.config.ConfigProperties;
import grails.core.GrailsApplication;
import grails.util.BuildSettings;
import org.grails.core.io.DefaultResourceLocator;

/**
* Core Auto-Configuration.
Expand All @@ -50,4 +56,14 @@ public ConfigProperties grailsConfigProperties(ObjectProvider<GrailsApplication>
return new ConfigProperties(grailsApplication.getIfAvailable().getConfig());
}

@Bean
@Order(0)
@ConditionalOnMissingBean
public DefaultResourceLocator grailsResourceLocator() throws IOException {
DefaultResourceLocator defaultResourceLocator = new DefaultResourceLocator();
defaultResourceLocator.setSearchLocations(List.of(BuildSettings.BASE_DIR.getCanonicalPath()));

return defaultResourceLocator;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2023 the original author or authors.
* Copyright 2004-2024 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.
Expand Down Expand Up @@ -35,7 +35,6 @@ import grails.util.Environment
import grails.util.GrailsUtil

import org.grails.beans.support.PropertiesEditor
import org.grails.core.io.DefaultResourceLocator
import org.grails.core.support.ClassEditor
import org.grails.dev.support.DevelopmentShutdownHook
import org.grails.spring.DefaultRuntimeSpringConfiguration
Expand Down Expand Up @@ -113,9 +112,6 @@ class CoreGrailsPlugin extends Plugin implements PriorityOrdered {
abstractGrailsResourceLocator {
searchLocations = [BuildSettings.BASE_DIR.absolutePath]
}
grailsResourceLocator(DefaultResourceLocator) { bean ->
bean.parent = 'abstractGrailsResourceLocator'
}

customEditors(CustomEditorConfigurer) {
customEditors = [(Class): ClassEditor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
Expand Down Expand Up @@ -156,6 +155,7 @@ public CachingGrailsConventionGroovyPageLocator groovyPageLocator(ObjectProvider
}

@Bean
@Order(-20)
@Primary
@ConditionalOnMissingBean
public ResourceLocator grailsResourceLocator(ObjectProvider<GrailsApplication> grailsApplication) {
Expand All @@ -177,8 +177,8 @@ public ResourceLocator grailsResourceLocator(ObjectProvider<GrailsApplication> g

@Bean
@ConditionalOnMissingBean
public ErrorsViewStackTracePrinter errorsViewStackTracePrinter(@Qualifier("grailsResourceLocator") ResourceLocator grailsResourceLocator) {
return new ErrorsViewStackTracePrinter(grailsResourceLocator);
public ErrorsViewStackTracePrinter errorsViewStackTracePrinter(ObjectProvider<ResourceLocator> grailsResourceLocator) {
return new ErrorsViewStackTracePrinter(grailsResourceLocator.getObject());
}

@Bean
Expand Down

0 comments on commit 36df0c7

Please sign in to comment.