spring boot tomcat termination - spring

I have exactly the same issue like that one: Terminating mvn spring-boot:run doesn't stop tomcat
The answer there says that it only happens on Windows but it's not actually true. I'm running spring boot on OSX with Intellij and when I stop the spring boot application the embedded tomcat is still running. The is the simple sample app from spring boot tutorial. Any solutions?

i have exactly the same issue within intellij on MAC (spring boot 1.1.6.RELEASE).
i worked around it by using spring boot actuator which offers a rest endpoint (Post) to shutdown the app:
localhost:port/shutdown
this can be called by commandline: e.g. curl -X POST localhost:port/shutdown
to enable spring boot actuator add the following compile dep:
org.springframework.boot:spring-boot-starter-actuator
i created a gradle task bootStop which does run this cmd for me.
you could do the same in maven or
you can just call it from cmd line (also trough the intellij terminal)
Especially if you want to use debugging, you should wrap the curl cmd given above in a gradle/maven task.
See working example (gradle) here

Here is a maven example for spring boot actuator to configure HTTP endpoint to shutdown a spring boot web app:
1.Maven Pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.application.properties:
#No auth protected
endpoints.shutdown.sensitive=false
#Enable shutdown endpoint
endpoints.shutdown.enabled=true
All endpoints are listed here:
3.Send a post method to shutdown the app:
curl -X POST localhost:port/shutdown

I have met the same issue and as result I had to review all solutions on this page and related one. No one is good for me. That is why I have made small research and it is appeared that problems with captured TCP port happen just because neither Gradle nor mvn knows nothing about child manipulation with TCP port.
So instead of killing process just use command:
$ gradlew –stop
(I hope the same exists for mvn)
This command gracefully closes daemons started by Gradle and frees captured by Tomcat ports.

Following the previous answer, this property is deprecated now, so replace it with:
management.endpoint.shutdown.enabled=true

A simpler solution is to create a "Spring Boot" configuration and use that to start your app instead of the "Gradle" configuration. The "Spring Boot" configuration does not experience this issue.

Related

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

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.

Basic "Hello World" Spring Boot application in IDEA doesn't work

I can't decide if there is a problem with the instructions in the spring.io tutorial or if there's something wrong with IDEA. Some help would be nice.
I'm following a guide at spring.io to create a simple blog application. I've used the spring initializr to create the application as directed (using Gradle, JDK 1.8, Kotlin) and I cannot run the application from a Spring Boot Run/Debug Configuration. It works only when I run the gradle "bootRun" task, but running through IntelliJ yields a Whitelabel Error Page.
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Additionally, the Spring Boot output in my console shows that the MustacheAutoConfiguration class could not find the /templates/ folder in my classpath.
2019-11-19 13:06:07.136 WARN 11840 --- [ restartedMain] o.s.b.a.m.MustacheAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
My Spring Boot Run/Debug configuration for BlogApplication has "Use classpath of module: blog.main".
Is there something else I'm missing here?
Did run the application after cloning from the github source. It runs just fine from intellj idea. Tested on JDK 13, 11 and 8
and the configuration for Boot run from intellj idea is bellow.
So I would suggest checking your gradle configuration of intelljidea.
This appears to be a known issue at the moment. See: https://youtrack.jetbrains.com/issue/IDEA-221673

tomcat7-maven-plugin to deploy spring boot with appropriate spring profile selected

My goal is to be able to use the tomcat-maven plugin to deploy my spring boot application from the command line where an argument is supplied that tells spring which profile to use like this:
mvn tomcat7:deploy -Dspring.profiles.active="dev"
I've tried several different things such as the solution described here but the default application.properties is still always selected.
The only way that I've been able to get the application-dev.properties selected is by using
mvn spring-boot:run -Dspring.profiles.active="dev"
But we don't want to have tomcat packaged in our war
I'm new to maven and spring boot and I've been spinning my wheels for the better part of a a day now so any advice would be appreciated.
Consider using MAVEN_OPTS environment variable to set VM argument. (Linux/osx) example you would need to execute before your maven goal:
export MAVEN_OPTS="-Dspring.profiles.active=dev"
I found out the issue and I was able to get the correct profile selected using
export SPRING_PROFILES_ACTIVE=dev. The problem that I was having was when I was starting my local tomcat server through the eclipse UI my environment variables were being ignored. When starting tomcat through startup.bat the environment variable gets used and spring uses the correct profile.

How to use Websphere liberty in spring boot application

I want to use Websphere liberty in spring boot application instead of tomcat server. If I am correct it is not supported out of the box. How can I configure spring boot/websphere liberty to achieve this?
Using the Liberty app accelerator you can download a zip containing a Maven buildable 'Spring Boot with Spring MVC' app as your starting point. Just run mvn install and you'll get the app running at http://localhost:9080/myLibertyApp/
Actually, you can now create runnable jar files with WebSphere Liberty. You need v8.5.5.9 or higher. Create a runnable jar this way:
server package {server name} --archive={jar name}.jar --include=minify,runnable
Resultant jar can be run as you'd expect:
java -jar {jar name}.jar
Since very recently (May 2018) you can deploy a Spring Boot jar with Liberty, as it seems. See https://developer.ibm.com/wasdev/blog/2018/05/11/spring-boot-applications-on-liberty/. Haven't tried it out yet, though.

Confuse of run Spring boot 1.3.0 application and specify certain profile

When I use spring boot 1.3.0 rc1, when run application by
mvn spring-boot:run
in console it will output
no profile actived
when you run application with
mvn spring-boot:run -Dspring.profiles.active=test
in console, in will output
profile test are activated
But yesterday when I changed to 1.3.0 release and run application in production,
java -Dspring.profiles.active=production -jar myapp.jar
I can't find above output in console.
In addition, I think it will only load appication-production.properties if you specified production profile, but it not, it still load application.properties.
So all these let me feel confuse and mislead me think prodcution profile cannot effect and run application by this way that is java -jar your.jar could not support -Dspring.profiles.active, meantime my colleague waiting for using my service so it give me many pressure.
Can anyone could explain it ?

Resources