@@ -19,24 +19,16 @@ import grails.config.Settings
1919import grails.core.GrailsControllerClass
2020import grails.plugins.Plugin
2121import grails.util.GrailsUtil
22- import groovy.transform.CompileStatic
2322import groovy.util.logging.Slf4j
2423import org.grails.core.artefact.ControllerArtefactHandler
2524import org.grails.plugins.web.servlet.context.BootStrapClassRunner
2625import org.grails.web.errors.GrailsExceptionResolver
27- import org.grails.web.servlet.mvc.GrailsDispatcherServlet
2826import org.grails.web.servlet.mvc.TokenResponseActionResultTransformer
2927import org.grails.web.servlet.view.CompositeViewResolver
3028import org.springframework.beans.factory.support.AbstractBeanDefinition
31- import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean
3229import org.springframework.context.ApplicationContext
33- import org.springframework.util.ClassUtils
34- import org.springframework.web.multipart.support.StandardServletMultipartResolver
35- import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
36- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
3730import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
3831import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
39- import jakarta.servlet.MultipartConfigElement
4032
4133/**
4234 * Handles the configuration of controllers for Grails.
@@ -61,15 +53,6 @@ class ControllersGrailsPlugin extends Plugin {
6153 def config = application. config
6254
6355 boolean useJsessionId = config. getProperty(Settings . GRAILS_VIEWS_ENABLE_JSESSIONID , Boolean , false )
64- String uploadTmpDir = config. getProperty(Settings . CONTROLLERS_UPLOAD_LOCATION , System . getProperty(" java.io.tmpdir" ))
65- long maxFileSize = config. getProperty(Settings . CONTROLLERS_UPLOAD_MAX_FILE_SIZE , Long , 128000L )
66- long maxRequestSize = config. getProperty(Settings . CONTROLLERS_UPLOAD_MAX_REQUEST_SIZE , Long , 128000L )
67- int fileSizeThreashold = config. getProperty(Settings . CONTROLLERS_UPLOAD_FILE_SIZE_THRESHOLD , Integer , 0 )
68- boolean isTomcat = ClassUtils . isPresent(" org.apache.catalina.startup.Tomcat" , application. classLoader)
69- String grailsServletPath = config. getProperty(Settings . WEB_SERVLET_PATH , isTomcat ? Settings . DEFAULT_TOMCAT_SERVLET_PATH : Settings . DEFAULT_WEB_SERVLET_PATH )
70- int resourcesCachePeriod = config. getProperty(Settings . RESOURCES_CACHE_PERIOD , Integer , 0 )
71- boolean resourcesEnabled = config. getProperty(Settings . RESOURCES_ENABLED , Boolean , true )
72- String resourcesPattern = config. getProperty(Settings . RESOURCES_PATTERN , String , Settings . DEFAULT_RESOURCE_PATTERN )
7356
7457 if (! Boolean . parseBoolean(System . getProperty(Settings . SETTING_SKIP_BOOTSTRAP ))) {
7558 bootStrapClassRunner(BootStrapClassRunner )
@@ -83,8 +66,6 @@ class ControllersGrailsPlugin extends Plugin {
8366
8467 " ${ CompositeViewResolver.BEAN_NAME} " (CompositeViewResolver )
8568
86- multipartConfigElement(MultipartConfigElement , uploadTmpDir, maxFileSize, maxRequestSize, fileSizeThreashold)
87-
8869 def handlerInterceptors = springConfig. containsBean(" localeChangeInterceptor" ) ? [ref(" localeChangeInterceptor" )] : []
8970 def interceptorsClosure = {
9071 interceptors = handlerInterceptors
@@ -93,17 +74,6 @@ class ControllersGrailsPlugin extends Plugin {
9374 annotationHandlerMapping(RequestMappingHandlerMapping , interceptorsClosure)
9475 annotationHandlerAdapter(RequestMappingHandlerAdapter )
9576
96- // add Grails webmvc config
97- webMvcConfig(GrailsWebMvcConfigurer , resourcesCachePeriod, resourcesEnabled, resourcesPattern)
98-
99- // add the dispatcher servlet
100- dispatcherServlet(GrailsDispatcherServlet )
101- dispatcherServletRegistration(DispatcherServletRegistrationBean , ref(" dispatcherServlet" ), grailsServletPath) {
102- loadOnStartup = 2
103- asyncSupported = true
104- multipartConfig = multipartConfigElement
105- }
106-
10777 for (controller in application. getArtefacts(ControllerArtefactHandler . TYPE )) {
10878 log. debug " Configuring controller $controller . fullName "
10979 if (controller. available) {
@@ -128,55 +98,6 @@ class ControllersGrailsPlugin extends Plugin {
12898 }
12999 } }
130100
131-
132- @CompileStatic
133- static class GrailsWebMvcConfigurer implements WebMvcConfigurer {
134-
135- private static final String [] SERVLET_RESOURCE_LOCATIONS = [ " /" ]
136-
137- private static final String [] CLASSPATH_RESOURCE_LOCATIONS = [
138- " classpath:/META-INF/resources/" , " classpath:/resources/" ,
139- " classpath:/static/" , " classpath:/public/" ]
140-
141- private static final String [] RESOURCE_LOCATIONS
142- static {
143- RESOURCE_LOCATIONS = new String [CLASSPATH_RESOURCE_LOCATIONS . length
144- + SERVLET_RESOURCE_LOCATIONS . length]
145- System . arraycopy(SERVLET_RESOURCE_LOCATIONS , 0 , RESOURCE_LOCATIONS , 0 ,
146- SERVLET_RESOURCE_LOCATIONS . length)
147- System . arraycopy(CLASSPATH_RESOURCE_LOCATIONS , 0 , RESOURCE_LOCATIONS ,
148- SERVLET_RESOURCE_LOCATIONS . length, CLASSPATH_RESOURCE_LOCATIONS . length);
149- }
150-
151- boolean addMappings = true
152- Integer cachePeriod
153- String resourcesPattern
154-
155- GrailsWebMvcConfigurer (Integer cachePeriod , boolean addMappings = true , String resourcesPattern = ' /static/**' ) {
156- this . addMappings = addMappings
157- this . cachePeriod = cachePeriod
158- this . resourcesPattern = resourcesPattern
159- }
160-
161- @Override
162- public void addResourceHandlers (ResourceHandlerRegistry registry ) {
163- if (! addMappings) {
164- return
165- }
166-
167- if (! registry. hasMappingForPattern(" /webjars/**" )) {
168- registry. addResourceHandler(" /webjars/**" )
169- .addResourceLocations(" classpath:/META-INF/resources/webjars/" )
170- .setCachePeriod(cachePeriod)
171- }
172- if (! registry. hasMappingForPattern(resourcesPattern)) {
173- registry. addResourceHandler(resourcesPattern)
174- .addResourceLocations(RESOURCE_LOCATIONS )
175- .setCachePeriod(cachePeriod)
176- }
177- }
178- }
179-
180101 @Override
181102 void onChange ( Map<String , Object > event ) {
182103 if (! (event. source instanceof Class )) {
@@ -205,5 +126,4 @@ class ControllersGrailsPlugin extends Plugin {
205126 }
206127 }
207128 }
208-
209129}
0 commit comments