Skip to content

Commit a370d5c

Browse files
committed
14017 - fix - do not use bean replacement for jspViewResolver & ensure all view resolvers are lazy init
1 parent 7d094d4 commit a370d5c

File tree

5 files changed

+70
-23
lines changed

5 files changed

+70
-23
lines changed

grails-gsp/grails-layout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies {
4444
implementation platform(project(':grails-bom'))
4545
implementation project(':grails-web-common') // GrailsViewResolver
4646
implementation project(':grails-core') // for plugin & groovy
47-
implementation project(':grails-gsp-core') // for grails layout preprocessor
47+
implementation project(':grails-gsp') // for grails layout preprocessor & gsp configuration classes
4848

4949
runtimeOnly project(':grails-web-jsp')
5050

grails-gsp/grails-layout/src/main/groovy/org/apache/grails/web/layout/GrailsLayoutViewResolverPostProcessor.groovy

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
package org.apache.grails.web.layout
2121

22+
import org.grails.plugins.web.GroovyPagesPostProcessor
23+
import org.grails.web.servlet.view.GroovyPageViewResolver
2224
import org.springframework.beans.BeansException
2325
import org.springframework.beans.MutablePropertyValues
2426
import org.springframework.beans.factory.config.BeanDefinition
25-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory
2627
import org.springframework.beans.factory.config.RuntimeBeanReference
2728
import org.springframework.beans.factory.support.BeanDefinitionRegistry
2829
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
@@ -46,34 +47,39 @@ class GrailsLayoutViewResolverPostProcessor implements BeanDefinitionRegistryPos
4647

4748
private static final String GRAILS_VIEW_RESOLVER_BEAN_NAME = 'jspViewResolver'
4849
private static final String GROOVY_PAGE_LAYOUT_FINDER_BEAN_NAME = 'groovyPageLayoutFinder'
49-
int order = 0
50+
int order = GroovyPagesPostProcessor.ORDER - 1
5051
Class<?> layoutViewResolverClass = GrailsLayoutViewResolver
5152
String layoutViewResolverBeanParentName = null
5253
boolean markBeanPrimary = true
53-
5454
boolean enabled = true
5555

56-
@Override
57-
void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
58-
}
59-
6056
@Override
6157
void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
62-
if (enabled && registry.containsBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)) {
63-
BeanDefinition previousViewResolver = registry.getBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)
64-
registry.removeBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)
58+
if (enabled) {
59+
BeanDefinition innerViewDefinition
60+
if (registry.containsBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)) {
61+
innerViewDefinition = registry.getBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)
62+
registry.removeBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME)
63+
} else {
64+
// default to what GroovyPagesPostProcessor would
65+
innerViewDefinition = new GenericBeanDefinition()
66+
innerViewDefinition.beanClass = GroovyPageViewResolver
67+
innerViewDefinition.parentName = 'abstractViewResolver'
68+
innerViewDefinition.lazyInit = true
69+
}
6570

6671
GenericBeanDefinition beanDefinition = new GenericBeanDefinition()
6772
beanDefinition.beanClass = layoutViewResolverClass
73+
beanDefinition.lazyInit = true
6874
if (layoutViewResolverBeanParentName) {
6975
beanDefinition.parentName = layoutViewResolverBeanParentName
7076
}
7177
if (markBeanPrimary) {
7278
beanDefinition.primary = true
7379
}
7480
final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues()
75-
propertyValues.addPropertyValue('innerViewResolver', previousViewResolver)
76-
propertyValues.addPropertyValue('groovyPageLayoutFinder', new RuntimeBeanReference((String) GROOVY_PAGE_LAYOUT_FINDER_BEAN_NAME, false))
81+
propertyValues.addPropertyValue('innerViewResolver', innerViewDefinition)
82+
propertyValues.addPropertyValue('groovyPageLayoutFinder', new RuntimeBeanReference(GROOVY_PAGE_LAYOUT_FINDER_BEAN_NAME, false))
7783
registry.registerBeanDefinition(GRAILS_VIEW_RESOLVER_BEAN_NAME, beanDefinition)
7884
}
7985
}

grails-gsp/plugin/src/main/groovy/org/grails/plugins/web/GroovyPagesGrailsPlugin.groovy

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,8 @@ class GroovyPagesGrailsPlugin extends Plugin {
247247
cacheTimeout = gspCacheTimeout
248248
}
249249
}
250-
// Configure a Spring MVC view resolver
251-
jspViewResolver(GroovyPageViewResolver) { bean ->
252-
bean.lazyInit = true
253-
bean.parent = 'abstractViewResolver'
254-
}
250+
// Configure a Spring MVC view resolver if none is defined
251+
groovyPagesPostProcessor(GroovyPagesPostProcessor)
255252

256253
// Now go through tag libraries and configure them in Spring too. With AOP proxies and so on
257254
for (taglib in application.tagLibClasses) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.grails.plugins.web
21+
22+
import org.grails.web.servlet.view.GroovyPageViewResolver
23+
import org.springframework.beans.BeansException
24+
import org.springframework.beans.factory.support.BeanDefinitionRegistry
25+
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
26+
import org.springframework.beans.factory.support.GenericBeanDefinition
27+
import org.springframework.core.Ordered
28+
29+
/**
30+
* Registers a jspViewResolver bean definition if one does not already exist.
31+
*/
32+
class GroovyPagesPostProcessor implements BeanDefinitionRegistryPostProcessor, Ordered {
33+
34+
private static final String JSP_VIEW_RESOLVER_BEAN_NAME = 'jspViewResolver'
35+
public static final int ORDER = 0
36+
37+
int order = ORDER
38+
39+
@Override
40+
void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
41+
if (!registry.containsBeanDefinition(JSP_VIEW_RESOLVER_BEAN_NAME)) {
42+
GenericBeanDefinition beanDefinition = new GenericBeanDefinition()
43+
beanDefinition.beanClass = GroovyPageViewResolver
44+
beanDefinition.parentName = 'abstractViewResolver'
45+
beanDefinition.lazyInit = true
46+
registry.registerBeanDefinition(JSP_VIEW_RESOLVER_BEAN_NAME, beanDefinition)
47+
}
48+
}
49+
}

grails-test-examples/gsp-sitemesh3/src/integration-test/groovy/EndToEndSpec.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import spock.lang.PendingFeature
2424
@Integration
2525
class EndToEndSpec extends ContainerGebSpec {
2626

27-
@PendingFeature
2827
def 'simple layout'() {
2928
when:
3029
go('endToEnd/simpleLayout')
@@ -35,7 +34,6 @@ class EndToEndSpec extends ContainerGebSpec {
3534
</body></html>"""
3635
}
3736

38-
@PendingFeature
3937
def 'title in subtemplate'() {
4038
when:
4139
go('endToEnd/titleInSubtemplate')
@@ -58,7 +56,6 @@ class EndToEndSpec extends ContainerGebSpec {
5856
</body></html>"""
5957
}
6058

61-
@PendingFeature
6259
def 'parameters'() {
6360
when:
6461
go('endToEnd/parameters')
@@ -67,7 +64,6 @@ class EndToEndSpec extends ContainerGebSpec {
6764
pageSource == """<html><head></head><body><h1>pageProperty: here!</h1></body></html>"""
6865
}
6966

70-
@PendingFeature
7167
def 'parameters with logic'() {
7268
when:
7369
go('endToEnd/parametersWithLogic')
@@ -76,7 +72,6 @@ class EndToEndSpec extends ContainerGebSpec {
7672
pageSource == "<html><head></head><body>good</body></html>"
7773
}
7874

79-
@PendingFeature
8075
def 'multiline title'() {
8176
when:
8277
go('endToEnd/multilineTitle')

0 commit comments

Comments
 (0)