[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"global-header-tutorials-static":3,"article-configure-profile-in-spring-boot":4,"initial-similar-fetch":24},[],{"alias":5,"title":6,"description":7,"content":8,"thumbnail":9,"keywords":10,"categories":18,"tags":21,"createdAt":23},"configure-profile-in-spring-boot","Configure different spring profiles in spring boot application","Managing Spring Boot profiles for different environments along with Docker","{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Spring profiles provide a way to create application config for different environments, i.e, dev, qa, stage, production, etc.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"In this tutorial, we are going to learn how we can set up the Spring application config for different environments in different ways.\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":2},\"content\":[{\"type\":\"text\",\"text\":\"Defining Profiles\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"We can define the profile in properties, a YAML file, or directly inside the code.\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"Using Property\u002FYAML Files\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"We can define the configuration  inside a properties file and separate it for different environments. For example, we can create \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"application-{profile}.properties\"},{\"type\":\"text\",\"text\":\" or \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"application-{profile}.yml\"},{\"type\":\"text\",\"text\":\"  i.e \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"application-{dev}.yml\"},{\"type\":\"text\",\"text\":\"  for development \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"application-{prod}.yml\"},{\"type\":\"text\",\"text\":\"  for production.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"marks\":[{\"type\":\"bold\"},{\"type\":\"code\"}],\"text\":\"application-dev.yml\"},{\"type\":\"text\",\"text\":\" (Development specific):\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"server:\\n  port: 8081\\nspring:\\n  datasource:\\n    url: jdbc:h2:mem:devdb\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"marks\":[{\"type\":\"bold\"},{\"type\":\"code\"}],\"text\":\"application-prod.yml\"},{\"type\":\"text\",\"text\":\" (Production specific):\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"spring:\\n  datasource:\\n    url: jdbc:mysql:\u002F\u002Fprod-server:3306\u002Fproddb\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"Multi Profile Single File Config\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"We can also configure all the configs for different environments in a single file. For this spring, provide the three dashes \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"---\"},{\"type\":\"text\",\"text\":\" to separate the environments.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Inside \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"application.yml\"},{\"type\":\"text\",\"text\":\":\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"---\\nspring.config.activate.on-profile: dev\\nserver:\\n  port: 8081\\nspring:\\n  datasource:\\n    url: jdbc:h2:mem:devdb\\n\\n---\\nspring.config.activate.on-profile: prod\\nspring:\\n  datasource:\\n    url: jdbc:mysql:\u002F\u002Fprod-server:3306\u002Fproddb\\n\\n---\\nspring.config.activate.on-profile: docker\\nserver.port: 8080\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"In Java Code\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"We can set the spring profile for specific spring beans or a configuration class to restrict for only the active profile i.e the beans or configuration file will load only the corresponding profile is active. This can be done using \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"@Profile\"},{\"type\":\"text\",\"text\":\" annotation.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"For example:\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"@Configuration\\n@Profile(\\\"dev\\\")\\npublic class DevDataConfig {\\n    \\n    @Bean\\n    public DataSource dataSource() {\\n        \u002F\u002F Returns a lightweight development database\\n        return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();\\n    }\\n}\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":2},\"content\":[{\"type\":\"text\",\"text\":\"Activating Profiles\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"We have configured the profiles in different ways; let's look at how to activate these profiles.\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"Using Command Line\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"While running our jar file, we can pass the spring profile as\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"bash\"},\"content\":[{\"type\":\"text\",\"text\":\"java -jar myapp.jar --spring.profiles.active=prod\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"Via JVM System Properties\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"bash\"},\"content\":[{\"type\":\"text\",\"text\":\"java -Dspring.profiles.active=dev -jar myapp.jar\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"Running Docker Container\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"If we are using a Docker container to run the application, we can set the environmental files in the Docker run command. This is very useful if you wanna hide the configuration data in production from development teams for security reasons.\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"bash\"},\"content\":[{\"type\":\"text\",\"text\":\"docker run -d \\\\\\n  --name csbyte \\\\\\n  -p 8081:8080 \\\\\\n  -v $(pwd)\u002Fapplication-prod.yml:\u002Fapp\u002Fconfig\u002Fapplication.yml \\\\\\n  -e SPRING_PROFILES_ACTIVE=prod\\n  csbyte\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Here, \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"-v $(pwd)\u002Fapplication-prod.yml:\u002Fapp\u002Fconfig\u002Fapplication.yml\"},{\"type\":\"text\",\"text\":\"  This will use the current directory file as the config properties file.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"-e SPRING_PROFILES_ACTIVE=prod\"},{\"type\":\"text\",\"text\":\"  this will activate the code-based profiling as mentioned earlier i.e \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"@Profile(\\\"prod\\\")\"},{\"type\":\"text\",\"text\":\".\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"By utilizing the profiling in a Spring Boot application, we can develop a highly maintainable, secure application.\"}]}]}","\u002Fuploads\u002Fthumbnails\u002F59a52e59-4b56-469d-8902-41af5e0f13dd_Spring-profil.jpeg",[11,12,13,14,15,16,17],"programming","coding","spring-boot-4","java","spring","spring-boot","spring-framework-7",[19,20],"Spring Framework","Spring Boot",[15,16,22],"deployment","2026-06-20T04:51:27.098Z",[25,32,38,44,50,56,62,68,73,79,85,91,97,103,109],{"alias":26,"title":27,"description":28,"thumbnail":29,"createdAt":30,"tutorialAlias":31,"lessonAlias":31},"spring-boot-multi-stage-build-with-docker","Creating spring boot multi-stage build with docker","How to create a Spring Boot multi-stage build with Docker","\u002Fuploads\u002Fthumbnails\u002F8931e2f7-a669-4fbb-855b-5ebe396f462e_multi-stage-build-docke.jpeg","2026-06-20T06:34:41.356Z",null,{"alias":33,"title":34,"description":35,"thumbnail":36,"createdAt":37,"tutorialAlias":31,"lessonAlias":31},"global-exception-handling-in-spring-boot","Implementing Robust Global Exception Handling in Spring Boot","How to Handle Errors in Spring Boot: An Architectural Guide","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F554489e1-d142-4ea5-a393-994a13d7b113_exception-handling.png","2026-06-12T17:15:16.253Z",{"alias":39,"title":40,"description":41,"thumbnail":42,"createdAt":43,"tutorialAlias":31,"lessonAlias":31},"spring-boot-create-libraries-gradle","Building Reusable Spring Boot Libraries with Gradle","Architectural Guide: Building Reusable Spring Boot Libraries with Gradle","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002Ff4fb088d-1018-4d2b-ae6c-cdd5d0fd60ae_spring-Initializr.png","2026-06-12T15:55:20.994Z",{"alias":45,"title":46,"description":47,"thumbnail":48,"createdAt":49,"tutorialAlias":31,"lessonAlias":31},"multi-build-project-gradle-spring-boot","Setting up a multi-project build in Gradle for Spring Boot","How to set up a multi-project build in Gradle for Spring Boot","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002Fd43933e4-a7a3-404b-a300-8f02db98f549_multi-build-project.png","2026-06-12T04:15:23.045Z",{"alias":51,"title":52,"description":53,"thumbnail":54,"createdAt":55,"tutorialAlias":31,"lessonAlias":31},"java-version-mismatch-gradle","Java Version Mismatch for Gradle Build","How to Fix Gradle Error: Dependency requires at least JVM runtime version 17. This build uses a Java 8 JVM","\u002Fuploads\u002Fthumbnails\u002Fa4c6c910-5623-4db9-93f5-a515135adb99_gradle_version_mismatc.jpeg","2026-06-09T12:15:21.729Z",{"alias":57,"title":58,"description":59,"thumbnail":60,"createdAt":61,"tutorialAlias":31,"lessonAlias":31},"constructor-confusion-in-spring","Constructor Confusion in Spring Framework","Constructor Confusion and how to handle it in Spring Framework","\u002Fuploads\u002Fthumbnails\u002Fd0f09fc0-e1f9-49d1-bf9a-7d1c41050196_di_confusio.jpeg","2026-05-21T14:13:31.437Z",{"alias":63,"title":64,"description":65,"thumbnail":66,"createdAt":67,"tutorialAlias":31,"lessonAlias":31},"dependency-pull-lookup-spring","Dependency Pull and Contextualized Dependency Lookup in Spring Framework","Dependency Pull and Contextualized Dependency Lookup IoC Types in Spring Framework","\u002Fuploads\u002Fthumbnails\u002Fd1132443-313b-4dce-b713-55f356ef6051_depndency_pull.png","2026-05-20T15:26:06.494Z",{"alias":69,"title":70,"description":70,"thumbnail":71,"createdAt":72,"tutorialAlias":31,"lessonAlias":31},"types-of-dependency-injection-spring","Types of Dependency Injection in Spring Framework","\u002Fuploads\u002Fthumbnails\u002Fafb32399-6dda-41c4-b07c-7decb8257bbb_di_constructor_sette.jpeg","2026-05-19T17:01:51.972Z",{"alias":74,"title":75,"description":76,"thumbnail":77,"createdAt":78,"tutorialAlias":31,"lessonAlias":31},"spring-framework-project-for-gradle-with-intellij-idea","How to create a clean Spring Framework project for Gradle with IntelliJ IDEA","Create a clean Spring Framework project for Gradle with IntelliJ IDEA","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F0e4abad5-17e2-4311-8cf0-7d8f67af975a_spring-framework.png","2026-05-19T10:28:20.866Z",{"alias":80,"title":81,"description":82,"thumbnail":83,"createdAt":84,"tutorialAlias":31,"lessonAlias":31},"spring-dependency-injection-and-inversion-control","Dependency Injection (DI) and Inversion of Control (IoC) in Spring","Mastering Dependency Injection (DI) and Inversion of Control (IoC) in Spring: A Practical Guide for Building a Notification System","\u002Fuploads\u002Fthumbnails\u002F53c64b94-f188-40b4-9ae9-ad97612d688b_spring_d.jpeg","2026-05-19T05:31:45.138Z",{"alias":86,"title":87,"description":88,"thumbnail":89,"createdAt":90,"tutorialAlias":31,"lessonAlias":31},"setting-nginx-ssl-for-spring-boot-application","Setup Nginx and SSL for Spring Boot Application","Setting Nginx as a reverse proxy in our Spring Boot application","\u002Fuploads\u002Fthumbnails\u002F5433c987-9e86-4d90-9cce-a831d1598ba4_spring-boot-nginx.png","2026-05-04T05:36:23.075Z",{"alias":92,"title":93,"description":94,"thumbnail":95,"createdAt":96,"tutorialAlias":31,"lessonAlias":31},"deploy-spring-boot-application-with-docker","Deploy Spring Boot Application with Docker on Ubuntu Server","The ultimate guide to deploying our Spring Boot application with Docker on an Ubuntu server","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F55a11844-d1e9-4e83-80e5-c6bb6df7d58b_intellij-idea-build.png","2026-05-03T05:58:55.642Z",{"alias":98,"title":99,"description":100,"thumbnail":101,"createdAt":102,"tutorialAlias":31,"lessonAlias":31},"how-to-install-and-setup-the-docker-on-ubuntu","How to install and setup the docker on Ubuntu","Setting up Docker in Ubuntu Linux","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F6c8baf8b-90b9-486c-8a92-56621ea6a234_show_container.png","2026-05-02T12:15:48.659Z",{"alias":104,"title":105,"description":106,"thumbnail":107,"createdAt":108,"tutorialAlias":31,"lessonAlias":31},"how-to-deploy-nuxt-app-in-ubuntu-server","How to deploy Nuxt app in Ubuntu Server","Deploy Nuxt App in Linux VM","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F808571e8-1ce9-4e1b-901f-7afd81f4c7df_pm2.png","2026-05-02T08:11:55.437Z",{"alias":110,"title":111,"description":112,"thumbnail":113,"createdAt":114,"tutorialAlias":31,"lessonAlias":31},"how-to-deploy-our-nuxt-application-to-cloudflare","How to deploy our nuxt application to cloudflare","Deploy our Nuxt application to Cloudflare using Wrangler","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F19c8ef54-4006-4bfa-a07d-b2dd5e401c22_nuxt_deploy.png","2026-05-02T02:23:45.510Z"]