Grails - the requested resource is not available when adding a new method to the controller interactively
I am new to Grails learning the basics. One of the first things I did was to follow the presentation at https://grails.org/learn . According to this, it should be possible to add a new method to the controller when the application is running interactively (launched by the launch target) and access that method as an action without having to restart the application.
When I tried to do this, I got a 404 error from the web server with the explanation, "The requested resource is not available." The new method works fine after restarting the application.
I use:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
$ java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode)
$ grails -version
Grails version: 2.4.3
Actions I did:
$ grails create-app grailsapp
| Created Grails Application at /home/marci/grailsapp
$ cd grailsapp/
$ grails
| Daemon Started
grails> create-controller hello
| Compiling 10 source files
| Compiling 131 source files
| Created file grails-app/controllers/grailsapp/HelloController.groovy
| Created file grails-app/views/hello
| Created file test/unit/grailsapp/HelloControllerSpec.groovy
grails>
I have implemented index()
in grails-app/controllers/grailsapp/HelloController.groovy
:
package grailsapp
class HelloController {
def index() {
render "index"
}
}
Saved file, launched the application:
grails> run-app
| Running Grails application
| Server running. Browse to http://localhost:8080/grailsapp
| Application loaded in interactive mode. Type 'stop-app' to shutdown.
| Enter a script name to run. Use TAB for completion:
grails>
Tested http://localhost:8080/grailsapp/hello/index
in browser, works great.
Now I have added another method:
package grailsapp
class HelloController {
def index() {
render "index"
}
def somemethod() {
render "somemethod"
}
}
The saved file. Grails seems to have noticed the source code change and recompiled the file:
| Compiling 1 source files
| Compiling 1 source files.
| Compiling 1 source files..
| Compiling 1 source files...
| Compiling 1 source files....
| Compiling 1 source files.....
grails>
Now if I try to access the new method by URL http://localhost:8080/grailsapp/hello/somemethod
from the browser, Tomcat says:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.55
Please note that the message is empty. If I try to access a method that doesn't exist, I get the message, so another error occurs. For example http://localhost:8080/grailsapp/hello/doesnotexist
:
HTTP Status 404 - /grailsapp/hello/doesnotexist
type Status report
message /grailsapp/hello/doesnotexist
description The requested resource is not available.
Apache Tomcat/7.0.55
If I restart the app interactively and retry the action somemethod
, then it works fine.
grails> stop-app
| Server Stopped
grails> run-app
| Running Grails application
| Server running. Browse to http://localhost:8080/grailsapp
| Application loaded in interactive mode. Type 'stop-app' to shutdown.
| Enter a script name to run. Use TAB for completion:
grails>
Now http://localhost:8080/grailsapp/hello/somemethod
return the expected response.
My question is, should the new action be available without reloading as shown in the presentation? Is this a bug in the 2.4.3 Grails release? Or do I need to do something else to activate this feature?
Thanks in advance,
Marton
source to share
if the new action is available without reloading, as demonstrated in the presentation?
Yes.
Is this a bug in version 2.4.3 of Grails?
Yes.
Or do I need to do something else to activate this feature?
No, you don't need to do anything else.
The reboot agent should work when you are online, but apparently not. If you file an issue at https://jira.grails.org/browse/GRAILS we can take a look at it.
Thanks for the feedback.
source to share