////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== controllers



=== Purpose


A plugin that configures core Grails MVC architecture using the underlying Spring MVC component model


=== Examples


A controller:

[source,groovy]
----
class BookController {
    def list() {
        [books:Book.list()]
    }
}
----

A tag library:

[source,groovy]
----
import java.text.SimpleDateFormat

class FormatTagLib {
    def dateFormat = { attrs ->
        out << new SimpleDateFormat(attrs.format).format(attrs.value)
    }
}
----


=== Description


This plugin configures Grails to use Spring MVC at its core to deal with web requests. The plugin sets up the `GrailsDispatcherServlet` and necessary Spring beans (see below) for controllers, tag libraries and Groovy Server Pages (GSP)

Configured Spring Beans:

* `exceptionHandler` - An instance of link:{apiFromRef}org/grails/web/errors/GrailsExceptionResolver.html[GrailsExceptionResolver] for dealing with exceptions
* `groovyPageResourceLoader` - Configured in `development` mode only or when the `grails.gsp.view.dir` is set. This is a Spring ResourceLoader that knows how to load GSP views from the an arbitrary location
* `groovyPagesTemplateEngine` - An instance of link:{apiFromRef}org/grails/gsp/GroovyPagesTemplateEngine.html[GroovyPagesTemplateEngine], this class deals with rendering of GSP views
* `jspViewResolver` - An instance of link:{apiFromRef}org/grails/web/servlet/view/GrailsViewResolver.html[GrailsViewResolver] that knows how to resolve GSP views and is environment aware

The plugin also configures each Grails controller class as a prototyped Spring bean and each Grails tag library as a singleton Spring bean
