java – How do I dynamically load the file based on the profile in Spring MVC?

Hello, I'm learning Spring MVC and want to know how to dynamically load the file.

I add the file and the file I want to dynamically load the application properties file by using profiles. For example: dev, test, prod. I tried to use dynamic name application {profile} .properties and also tried profile comments. but unable to understand how they actually work. I have created another file.

  1. application-dev
  2. application test
  3. Application Prod

This property file contains my DB-related data. However, I do not know how to set a profile and how to load PropertySource based on a profile.
I have set the active profile in my appConfig file. Please help me understand how to configure profiles and using Spring MVC Java-based configuration. I have searched and found many solutions for the XML-based configuration, but found no suitable answer for the Java-based configuration.

@ComponentScan ({"com.project.configuration"})
@PropertySource (value = {"classpath:"})
public class HibernateConfiguration {

private environment env;

public LocalSessionFactoryBean sessionFactory () {
return sessionFactory;

public DataSource dataSource () {
/ * Load DB * /
Return dataSource;

public properties hibernateProperties () {

@Run over
public void onStartup (ServletContext servletContext) raises ServletException
super.onStartup (servletContext);
servletContext.setInitParameter ("", "dev");