I'm working on an application that utilizes the Spring Boot framework. I work exclusively out of IntelliJ, in which I've created a runtime configuration for Spring Boot. This configuration is IntelliJ-based and is capable of running and debugging the application utilizing the settings specified in both the project's application.properties and pom.xml files.
Up until about a week ago, my runtime configuration (upon debugging/running) launched the Spring Boot application, which in turn launched an embedded instance of Tomcat. Last week, without making any project-level setting changes, this configuration has started to run Jetty rather than Tomcat. Has anyone seen this?
Unfortunately, I'm not at liberty to share the properties or pom files in-depth, but I will point out that I have no mention of Jetty in either, and the following are listed as dependencies:
Thanks for taking a look!
Related
I am building a Spring Boot application using Bamboo. Is there any way I can read maven build related information like:
buildNumber and buildTimeStamp?
I have tried reading properties like below but they are not working.
#Value("${bamboo.buildNumber}")
private String buildNumber;
and
#Value("${buildNumber}")
private String buildNumber;
I think the bit I missing can be any of below:
Bamboo is not writing properties to Jar exported to Artifactory.
I am reading properties with wrong keys.
I am missing some POM configuration.
Any help is much appreciated.
The #Value notation reads values from a properties file when you run the spring application. There is no way that properties which existed in the Bamboo environment at the time that your spring app was built will be available when you run your spring app, unless you take steps to make them available.
You will need to build a .properties file during the Bamboo build, and have this packaged into your spring boot application.
I can't get my custom environment to run under Tomcat. It always loads the development profile.
I create a WAR with the following under Grails 4.0.5:
grails -Dgrails.env=qa war
The resulting grails.build.info looks correct:
info.app.version=2.0.7
info.app.name=myapp
grails.env=qa
info.app.grailsVersion=4.0.5
However, when I drop it into Tomcat 8 and run, I get this:
[ost-startStop-1] com.myapp.ApplicationLoader : The following profiles are active: development
Running standalone, though, works just fine:
./gradlew -Dgrails.env=qa bootRun
grails.util.Environment, defines a number of pre-configured environments.
Environment APPLICATION
Environment CUSTOM
Environment DEVELOPMENT
Environment PRODUCTION
Environment TEST
In application.yml we get pre-configured development, test, and production environments. So if we want to add custom environments we add similarly. In your case it will be qa.
With Grails command line we can execute any command within the context of a specific environment. The format is:
grails [environment] [command name]
Suppose if want to create a WAR for the test environment you wound run:
grails test war
To target other environments you can pass a grails.env variable to any command:
grails -Dgrails.env=UAT run-app
I create a WAR with the following under Grails 4.0.5:
grails -Dgrails.env=qa war
Yes, all looks good as per grails documentation and configuration.
I have Created POC app for same with Grails 4.0.5 and also downloaded external tomcat apache-tomcat-8.5.63.
My application.yml with qa ENV:
Running standalone, though, works just fine:
./gradlew -Dgrails.env=qa bootRun
Yes. This also works fine.
So, now i have created war file with grails -Dgrails.env=qa war
Then i started my tomcat and dropped my poc-app-0.1.war file into tomcat.
when tomcat deployed/extracted my war, entered local url into browser.
You can see in above image, Environment is qa
So everything is running as i passed to env while creating war.
I tested with multiple environments, both pre-configured and custom environments. But did not got any issue like created war for qa and running on dev.
Also i have tested with java -jar poc-app-0.1.war and it's running on same env as we given.
Application details:
and tomcat version is apache-tomcat-8.5.63
It may be some versions or configuration issue with your app.
Please refer this link of my poc. Can you please try to create war and deploy in same way to your tomcat and let me know.
If you are still getting issue, then please share your minimal code or poc.
Even i got one more similar kind of issue on grails repo, please do refer this.
I have followed lot of documentation and references but still not able to reproduce your issue.
Links:
Environment class
Upgrade Doc
Command Line
API Doc
Conf Doc
I have an application built in Spring Tool Suite and using angular as well for frontend. I am building my maven and the deploying the war in Tomcat. While the Spring dev-tools work fine for any application when it is deployed form the tomcat container within STS but not when I put the war in external Tomcat. Is there any way to hotSwap the application other than blackboxing my javascript in Chrome. Can anyone list down the complete steps to follow. I'm a noob.
I have already put a dependency sping-devtools in maven. There are many answers related to that but none of them is working. It is a big project and takes 4 minutes to build and then I need to deploy it in tomcat which is a lot of burden.
Looks like you are looking to hot reload the static files. In IntelliJ, it's simple as saving your code changes and doing a Build Project CTRL + F9. It's even better if you install a Live Reload extension for your browser so that any changes made is refreshed automatically. There are also other similar options for compile & build automatically in IntelliJ as well other IDEs such as Eclipse.
I have a Spring Boot Gradle application with apply plugin: 'war'. I run the application on STS by right click > Run As > Spring Boot App. It runs fine. Now I make a change to the code and I want to redeploy (and better automatically). The only way I know now is to stop the server and run again. Is there any faster solution?
Spring-boot provide something called devtools which is a very neat feature.
Include this starter on your gradle build
compile("org.springframework.boot:spring-boot-devtools")
This will automatically restart whenever files on the classpath changes. So you don't have to manually stop and start server.
you can see more details here.
According to the Spring Boot Devtools docs, devtools won't run in "production mode"; that is, if you execute your Spring Boot app with java -jar .., then it won't use devtools' built-in JVM magic. However, the Spring Boot starter docs only show you one way of running your Spring Boot application...via java -jar....
So first I'm wondering: How do I run my Spring Boot app in non-production mode? I know you can run your app with Spring Boot CLI (e.g. spring run), but is that the only way?
Also, the same devtools docs mention you can explicitly remove the devtools jar from your production binary by using some excludeDevtools option, but they never explain where/how to use this. Any examples/ideas here?
1) One example of running a Spring Boot app in non-production mode (i.e. not from the JAR) is from an IDE (most specifically Eclipse or IntelliJ), where you can launch the application from the main method, or using the Spring Boot launch support. This is the most practical use of Dev Tools as it allows to continuously watch the changes in your application without restarting.
2) excludeDevTools is an option of the Spring Boot Maven Plugin http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/repackage-mojo.html or the Gradle plugin - see http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-repackage-configuration.
So in your case it would be
bootRepackage {
mainClass = 'demo.Application'
excludeDevtools = true
}
To start with Spring boot and devtools made development easier. Spring boot uses embedded servlet container ( tomcat,undertow,jetty) with this you can have production ready code even in non-production environment.
Coming to your question how to run Spring-boot application in non-production environments, we can run application directly from Spring tool suite IDE by right click -> run as Spring boot if it is local environment.
If the build tool used is maven then from command prompt mvn boot:run , if it is gradle then gradle bootRun from root folder of project location in command prompt. If you are packing your application as uber jar then Java -jar .., also if your environment is Linux you can start as a process.
Regarding ignoring devtools in production environment, Spring boot intelligently ignore devtools jar if we specify Spring-boot-devtools as optional scope in dependencies of your build tool(maven, gradle) . In gradle Spring boot gradle plugin takes care of ignoring devtools for final deployed jar or war
Update ::
To debug a Spring Boot application run with Gradle, as seen at http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-remote-debug-gradle-run596
Add this to your build.gradle file:
applicationDefaultJvmArgs = [
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" ]
In IntelliJ Idea IDE or STS, setup a new Debug configuration and in the options select "Remote". The defaults should be fine, but pay attention to the port number and transport type ("socket"). Have fun!