javatomcatwarurlmappings.groovygrails3

URL Mapping broken for actions other than index in standalone WAR for Grails 3 App


I'm new to GRAILS but I built a simple app and I'm trying to deploy it to tomcat.

If I run the app using:

grails prod run-app

everything works fine. However, if I build it to a war file

grails prod war

then either upload the war package to a tomcat server or run it directly like

java -Dgrails.env=prod -jar build\lib\app.war

then I get this strange behaviour where everything seems fine at first but whenever I click on a link for an action other than index, I get a 404 error. E.g.

     webapp:8080/employee           WORKS
     webapp:8080/employee/index     WORKS
     webapp:8080/employee/show/1    404 error
     webapp:8080/department         WORKS
     webapp:8080/department/show/1  404 error

etc.

In the above example webapp:8080/employee/show/1 should definitely be found because it is listed and linked from a table in the index.

Im having a huge amount of trouble getting to the bottom of it because I cant seem to find any feedback from a running war file whether I run it in tomcat or directly, even if I move environments to test or dev. Theres just nothing in the log files or stdout.

Here is my UrlMappings

package generico

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        // "/"(view:"/index")
        "/"(controller:"employee", action:"index")
        "500"(view:'/error')
        "404"(view:'/notFound')
    }
}

Again, everything works absolutely fine if I do "grails run-app" for any environment.

I appreciate any help. Thanks.


Solution

  • My problem was with Grails 3.2.1. After I updated to Grails 3.2.2, did a gradle clean, then repackaged, everything works fine.