Debug Spring Boot app from Intellij where service is started in a multi service docker-compose file? - spring-boot

I have a docker-compose YML file that includes multiple Spring Boot apps.
Is it possible to debug one of these Spring Boot apps from Intellij?

I guess it depends how the apps are started within the Docker container. One option could be starting the application in debug mode with the following in the Dockerfile of the app you want to debug:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar myApp.jar
Remember to build your container again and then attach a remote debugger with IntelliJ to the port 8000.

Related

How to specify JDBC URL in spring boot application in case of the MySQL running as a Kubernetes Service?

I have a java application with maven build. I have provided the k8 service name of the mysql in the application properties of the spring boot application. However, I get error as unknown host and the maven build fails. How do I overcome this?
Application properties:
spring.datasource.url=jdbc:mysql://mymysqlk8servicename/testdb
When I build the application using mvn clean install, the build fails with error as java.net.UnknownHostException.
For the record, I am running the maven build in the master machine of the Kubernetes cluster. Should I run the java application only as a Kubernetes service? Is it possible to just run the java application without deploying in the Kubernetes cluster?
If you do
kubectl get service
You should be able to see the servicename. Pay attention to the port too.

Manage build profiles/configs for Spring Boot application

I have written application using spring boot + scala with sbt and now I need to divide build configurations for dev and prod.
What has been done: created configs application.yml and application(-dev/prod).yml to start application locally, on dev and prod respectively.
What need to be done: find a way to configure spring boot profile (dev, prod) in javaopts or directly write corresponding config, also in javaopts.
I've tried to use these opts:
sbt service/run -Dspring.profiles.active=...
sbt service/run -Dspring.config.location=...
The answer is to configure active profile like this:
sbt service/run --spring.profiles.active=...

How to I externalize my configuration for my spring-boot war application?

I have a spring-boot war application that is packaged using Maven, and I need to deploy it as docker image. Now I am done with creating docker image, my current problem is how do I pass external configuration? I am not running my spring-boot application as java -jar myapp.war. The person responsible for deploying this image will need to pass the path of the configuration file to docker image.

Run multiple jar files from intellij idea and change, run and debug through.

So I basically want to debug through multiple jar files all different microservices that send/receive messages to/from each other's APIs. What I do at the moment is to run each jar files from my command line as java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 ***.jar and do a remote debugging with my intellij with the same port.
I was wondering whether it is possible to have all jar files into one configuration and start them all in one debugging session in Intellij?
Are the micro services runnable on a webserver like Tomcat? If so, you can download the webserver, add it to IntelliJ and deploy these three micro services in the same run configuration. You should then be able to debug that run configuration and debug these at the same time.

How to debug deployed Grails application

Is there any way to debug Grails application deployed to production server in Intellij IDEA or any other IDE?
You need to start your server in debug mode by adding something like this to the java process start script:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Then in IntelliJ open Run > Edit Configurations and select Defaults > Remote, where you can set the port you specified above to debug the remote JVM.
You can do the same in Eclipse.
Also you can use grails-debug run-app to debug Grails application. But I think it's not good choice for production
Also, starting from grails 2.3.0 the jvm is forked into the build vm and the application vm. Using --debug allow you to debug the build vm, and using --debug-fork allows you to debug the app vm. Grails 2.3 forked execution

Resources