Grails get stuck at "finished configuring Spring Security REST" - grails

I type grails run-app and it begins to run, but it gets stuck on the message:
----------------------------------------
Current config:
baseDir: db/migration/global
env: DEVELOPMENT
dataSource: default
url: jdbc:postgresql://localhost:5432/mydbapp
username: postgres
schemas: public
----------------------------------------
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security REST ...
... finished configuring Spring Security REST
It used to run fine like an hour ago. No strange logs or anything. Also, when hit ctrl+c in the terminal, grails will close, but when I run-app again, it will say something like:
Error Server failed to start for port 8080: Address already in use (Use --stacktrace to see the full trace)
Indicating that grails wasn't really terminated. Of course, I kill the app occupying 8080 and run-app again, but it's still getting stuck.

The port 8080 is been used for another thread. Try to find a java thread in your system that you don't recognize and stop it.
How to on windows
How to on Linux

In BuildConfig.groovy, change your apps port. Example:
grails.server.port.http = 8003
If you still get port in use, exit IntelliJ, goto Task Manager, sort by memory used, end any processes with IntelliJ or Grails.

If you are using liquibase database migration tool and if you somehow stopped it before it finishes it will put a lock at DATABASECHANGELOGLOCK table. Change it to LOCKED = false and it will start.

Related

Grails 5 app is constantly redeploying during development

I had been using Grails 3.3.2 for about 3-4 years now and never had this issue. I just recently started migrating our apps to Grails 5 and now this started happening. Everytime I save a change to a file (gson, groovy, etc) the app redeploys and I have to wait a good 5-6 seconds before I can test it (url becomes available).
In Grails 5 my console looks like this when I make changes:
Grails application running at http://localhost:8081 in environment: development
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
Grails application running at http://localhost:8081 in environment: development
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
Grails application running at http://localhost:8081 in environment: development
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
Grails application running at http://localhost:8081 in environment: development
Each one of those Grails application running [...] lines is a 5+ second delay I have to wait through before the app comes back up
When I would work on my 3.3.2 projects my console would look like this during changes
Grails application running at http://localhost:8081 in environment: development
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
File C:\Workspaces\Intellij\ecpp\grails-app\controllers\ecpp\service\LookupSvcController.groovy changed, recompiling...
I never had to wait, I could immediately refresh the page and see the changes. Needless to say, my DEV time has taken a hit having to stop and wait for a redeploy. Is there some configuration I missed while upgrading that I can set to resolve this?
This happens while running the app with gradlew bootRun as well as grailsw run-app
Grails 5.1.7
JDK: 11.0.13
I just recently started migrating our apps to Grails 5 and now this
started happening. Everytime I save a change to a file (gson, groovy,
etc) the app redeploys and I have to wait a good 5-6 seconds before I
can test it (url becomes available).
The behavior you described is expected and by design.
Older versions of Grails were configured by default with a reloading agent. Grails 5 is not. The default behavior you will get with Grails 5 is a recompile and restart. If you don't want that behavior you can remove the devtools from your build.
You didn't ask about configuring a reloading agent but if you are interested, see the Spring Boot Developer Tools and Spring Loaded section at https://docs.grails.org/5.1.7/guide/single.html#upgrading33x.

Caused by: org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /null/swagger-resources/configuration/ui

Getting the below exception while starting the spring boot application.
Exception:
Caused by: org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /null/swagger-resources/configuration/ui
Swagger gradle dependencies versions are as below
compile('io.springfox:springfox-swagger2:2.7.0')
compile('io.springfox:springfox-swagger-ui:2.7.0')
you need close like this browser tab.
my spring boot application port is 8888, when i close this tab and restart my spring boot application, the error is gone.
Hopefully it is the issue with IntelliJ editor. I'm running multiple microservices on different ports and shutting them down once the work is done, but IJ editor might have cached the port(which it already shut down) and causing this confusion and error. I have restarted the service with a different port, and the error is gone.
Note: In general, we will get BIND ERROR : Address already in use, if any other service is running on the same port.

3.0.0.M1 how to run on https connection

Trying Grails 3.0.0.M1, a lot has changed!
How would I run-app --https and how would I configure it that way also for the production-environment-war?
Many thanks!
First of all, Grails 3.0.0.M1 is not production ready, if thinking about making the move.
Major changes for Grails 3 include:
Built on top of Spring Boot
Introduction of Gradle as the build system
And many more (which is not relevant to this question)
In order to setup SSL for Spring Boot app, server.ssl.* setting has to be added to application.properties or application.yml file.
In Grails 3 it would correspond to application.yml under grails-app/conf. Below changes (as an example) would be required:
server:
port: 8443
ssl:
key-store: classpath:keystore.jks
key-store-password: secret
key-password: another-secret
which is equivalent to Configuring SSL in Spring Boot.
However, documentation is limited right now and is being worked on. So let Grails 3 brew more until its GA where it can be used in production environment.
Grails community will be more than happy if any issues/problems/enhancement is reported in Grails JIRA

How to solve cross domain errors when running two grails apps on localhost

I am trying to run-app my project with other wars/wars also running. So for example we have a war/ear that has legacy web services that I would like to access. My goal is to deploy those existing wars/ears with my run-app. I can deploy both separately, as grails run-app on port 8081 and jboss on port 8080. The problem was when I tried to do a ajax POST, DELETE, or PUT I get a cross-domain error because each app is on its own port. Is there a way to use run-app so that my grails project is at localhost:8080/grails and the webservices are at localhost:8080/webservices
Env: Grails 2.1.1
Server: Jboss (perfered) or vFabric tc Server (by dropping in existing war/war)
I don't believe that you can "run-app" both projects on the same port because you're running an embedded container. However, what you can do is check out the Grails CORS plugin which will allow other domains to access your grails app during run-app or otherwise.
http://grails.org/plugin/cors

HTTPS Grails application URL

My Grails app runs over HTTPS and in Config.groovy I've set:
environments {
development {
grails.serverURL = "https://localhost:8443/foo"
}
}
When I execute grails run-app to start the app in dev mode, the last message printed on the console is:
Server running. Browse to http://localhost:8082/foo
If I accidentally click on this URL to access the application, I get various errors due to the same-origin security policy (because https://localhost:8443 is a different host to http://localhost:8082).
Why is Grails prompting me to access my app via http://localhost:8082/foo when I've set grails.serverURL = "https://localhost:8443/foo"
Update
I changed the startup command to grails run-app -https and the last message printed on the console is now:
Server running. Browse to http://localhost:8082/foo or https://localhost:8443/foo
Why am I given the option of either HTTP or HTTPS, rather than just the latter? Also, I get this exception during startup:
http11.Http11Protocol Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
java.net.BindException: Address already in use <null>:8443
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:407)
I've checked if port 8443 is in use before I run this command (it isn't), but the server seems to startup despite this exception, so this is not a major concern.
Replace grails.serverURL with the code below.
Its possible to set the port with the following system properties:
grails.server.port = 8082
That should work for both http and https. To configure for just one:
grails.server.port.https = 8082
You need to use the --https parameter to run-app for Grails to respond to HTTPS and HTTP in development mode. At least according to the documentation.
Try using
grails run-app --https
Further more, the grails.serverURL is typically used by taglibs and plugins, and not the launching process as far as I can tell.
You can set the ssl port you want to run you application on via https in BuildConfig.groovy. You can add the following to your BuildConfig.groovy
//You can specify another port here to get rid of your startup exception
grails.server.port.https="8443"
grails.server.host="localhost"
Then try grails run-app -https and you should be able to run your app on the ssl port you defined or the default 8080 port

Resources