@@ -18,12 +18,16 @@ package org.codehaus.groovy.grails.plugins.web.mapping;
1818import grails.util.GrailsUtil
1919import org.codehaus.groovy.grails.web.mapping.*
2020import org.codehaus.groovy.grails.commons.*
21+ import org.springframework.context.ApplicationContext
22+ import org.springframework.aop.target.HotSwappableTargetSource
23+ import org.springframework.aop.framework.ProxyFactoryBean
24+
2125/**
22- * A plug-in that handles the configuration of URL mappings for Grails
23- *
24- * @author Graeme Rocher
25- * @since 0.4
26- */
26+ * A plug-in that handles the configuration of URL mappings for Grails
27+ *
28+ * @author Graeme Rocher
29+ * @since 0.4
30+ */
2731class UrlMappingsGrailsPlugin {
2832
2933 def watchedResources = [" file:./grails-app/conf/*UrlMappings.groovy" ]
@@ -32,24 +36,31 @@ class UrlMappingsGrailsPlugin {
3236 def dependsOn = [core :version]
3337
3438 def doWithSpring = {
35- grailsUrlMappingsHolder (UrlMappingsHolderFactoryBean ) {
39+ grailsUrlMappingsHolderBean (UrlMappingsHolderFactoryBean ) {
3640 grailsApplication = ref(" grailsApplication" , true )
37- }
38- }
39-
40- def doWithApplicationContext = { ctx ->
41- def beans = beans {
42- grailsUrlMappingsHolder(UrlMappingsHolderFactoryBean ) {
43- grailsApplication = ref(" grailsApplication" , true )
44- }
4541 }
46- ctx. registerBeanDefinition(UrlMappingsHolder . BEAN_ID , beans. getBeanDefinition(UrlMappingsHolder . BEAN_ID ))
42+ urlMappingsTargetSource(org.springframework.aop.target.HotSwappableTargetSource , grailsUrlMappingsHolderBean)
43+ grailsUrlMappingsHolder(ProxyFactoryBean ) {
44+ targetSource = urlMappingsTargetSource
45+ proxyInterfaces = [org.codehaus.groovy.grails.web.mapping.UrlMappingsHolder ]
46+ }
47+ }
48+
49+ def doWithApplicationContext = { ApplicationContext ctx ->
50+ def beans = beans(doWithSpring)
51+ beans. registerBeans(ctx)
4752 }
4853
4954 def onChange = { event ->
5055 if (application. isUrlMappingsClass(event. source)) {
5156 application. addArtefact( UrlMappingsArtefactHandler . TYPE , event. source )
52- doWithApplicationContext(event. ctx)
57+
58+ def factory = new UrlMappingsHolderFactoryBean (grailsApplication :application)
59+ factory. afterPropertiesSet()
60+ def mappings = factory. getObject()
61+
62+ HotSwappableTargetSource ts = event. ctx. getBean(" urlMappingsTargetSource" )
63+ ts. swap mappings
5364 }
5465 }
5566}
0 commit comments