Grails 2.3 Application initialization error: No bean named 'urlMappingsTargetSource' defined

I am using Grails 2.3.11. In BootStrap.groovy, I call:

def ctx = servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT)
HotSwappableTargetSource ts = ctx.getBean("urlMappingsTargetSource")

      

I am getting NoSuchBeanDefinitionException

12,09 21:55:44:084 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: No bean named 'urlMappingsTargetSource' is defined
   org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'urlMappingsTargetSource' is defined
   at BootStrap$_closure1.doCall(BootStrap.groovy:10)
   at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
   at grails.util.Environment.executeForEnvironment(Environment.java:301)
   at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
   at java.util.concurrent.FutureTask.run(FutureTask.java:166)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
   at java.lang.Thread.run(Thread.java:722)

      

This does not throw an exception when running the application in my development environment. However, if I create a war file and deploy to tomcat I get org.springframework.beans.factory.NoSuchBeanDefinitionException

This line worked fine when using Grails 2.1.0 and 2.2.4. I also tried Grails 2.3.9, but this also throws a NoSuchBeanDefinitionException.

I am also trying to use dependency injection but "urlMappingsTargetSource" is null

class BootStrap {

    def urlMappingsTargetSource

      

Does anyone else have this problem, or does anyone know why I am getting a NoSuchBeanDefinitionException?

Has anything changed the way this bean is loaded in Grails 2.3 vs Grails 2.2 or 2.1?

Any help or understanding would be much appreciated.

+3


source to share


1 answer


UrlMappingsGrailsPlugin.groovy contains the following code

    if (Environment.isDevelopmentMode() || Environment.current.isReloadEnabled()) {
        "org.grails.internal.URL_MAPPINGS_HOLDER"(UrlMappingsHolderFactoryBean) { bean ->
            bean.lazyInit = true
        }

        urlMappingsTargetSource(HotSwappableTargetSource, ref("org.grails.internal.URL_MAPPINGS_HOLDER")) { bean ->
            bean.lazyInit = true
        }

        grailsUrlMappingsHolder(ProxyFactoryBean) { bean ->
            bean.lazyInit = true
            targetSource = urlMappingsTargetSource
            proxyInterfaces = [UrlMappings]
        }
    } else {
        grailsUrlMappingsHolder(UrlMappingsHolderFactoryBean) { bean ->
            bean.lazyInit = true
        }
    }

      



If the envrionment is not in development mode or is reloaded, the beans are not initialized. I added beans to my .groovy resources and it worked

import org.codehaus.groovy.grails.web.mapping.UrlMappingsHolderFactoryBean
import org.springframework.aop.framework.ProxyFactoryBean
import org.springframework.aop.target.HotSwappableTargetSource

// Place your Spring DSL code here
beans = {
"org.grails.internal.URL_MAPPINGS_HOLDER"(UrlMappingsHolderFactoryBean) { bean ->
    bean.lazyInit = true
}

urlMappingsTargetSource(HotSwappableTargetSource, ref("org.grails.internal.URL_MAPPINGS_HOLDER")) { bean ->
    bean.lazyInit = true
}

grailsUrlMappingsHolder(ProxyFactoryBean) { bean ->
    bean.lazyInit = true
    targetSource = urlMappingsTargetSource
    proxyInterfaces = [org.codehaus.groovy.grails.web.mapping.UrlMappings]
}
}

      

+3


source







All Articles