{
"$type": "site.standard.document",
"path": "/deploying-spring-boot-to-amazon-elastic-beanstalk/",
"publishedAt": "2016-07-07T20:30:38.000Z",
"site": "at://did:plc:6gssgguzeecdttuw4gpdshg2/site.standard.publication/self",
"tags": [
"java",
"spring-boot",
"aws"
],
"textContent": "While there are a ton of guides on how to use spring boot, I was not able to find anything about how to deploy different configurations on Amazon's Elastic Beanstalk. Here is a how to on some of the options you have when deploying to Elastic Beanstalk. It does not matter if you are deploying via a jar or war the configuration methods are essentially the same.\n\nThe first thing we had to ensure is that we could override the configuration. This way we can provide settings specific to any one deployment. Spring-boot offers many ways to do this. There are several options for externalized configuration.\n\nUsing Spring Application JSON\n\nThe first option I looked into was using SPRING_APPLICATION_JSON to configure the properties for the installation. While this does work, there are several limitations when deploying to Elastic Beanstalk.\n\nThe first lesson I learned is that you can not set this value in the user interface. You can see my report here on stack overflow: http://stackoverflow.com/questions/38208301/spring-boot-amazon-elastic-beanstalk-ignores-spring-application-json/38224046#38224046. You can get this configuration to work using an .ebextensions folder and configuration in your jar/war.\n\nHere is an example configuration file.\n\n[Embedded code (GitHub Gist)]\n\nDon't forget to have gradle insert this into your war/jar file!\n\n[Embedded code (GitHub Gist)]\n\nWe ended up not going with this idea. The configuration JSON would up getting rather complex as we expand the config options with in our application.\n\nUsing Spring Profiles\n\nEnter spring boot profiles. This is exactly the feature you should be using for this type of deployment.\n\nProfiles allow you to provide a set of default settings, then override any settings you need to for a given environment. This is essentially the same as using the JSON config, but lets you have these settings in a config file not a JSON string.\n\nThe profile setting can be provided in Elastic Beanstalk's UI without any issues. Here is our production profile being loaded into the JVM:\n\n[Image: jvm-opts-1.png]\n\nYou can also load this via a system property called SPRING_PROFILES_ACTIVE.\n\nTo override any of your default settings just provide the profile specific value in that profile's configuration file. When using the default settings this is application-${profileName}.properties.\n\nThings to watch for!\n\nBe sure your default configuration is not setting spring.profiles.active this will override your provided profiles. If you want to ensure a given profile is also being loaded use spring.profiles.include.\n\nRead the original post with all embeds and interactive content at https://rants.broonix.ca/deploying-spring-boot-to-amazon-elastic-beanstalk/",
"title": "Deploying Spring-Boot to Amazon Elastic Beanstalk"
}