How to load application.properties in spring framework?

805 Views Asked by At

My spring application start's via WebApplicationInitializer.

public class WebAppInitializer implements WebApplicationInitializer
{
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException
    {
       ....
    }
}

I have Config class

@Configuration
@PropertySources({
    @PropertySource(value = "classpath:application.properties"))
})
public class MainConfig
{
  ....
}

And in application.properties file I try to override the spring and logging properties

logging.level.com.app=DEBUG
logging.level.org.springframework.web=DEBUG

The file application.properties is in the directory src/main/resources

But it has no effect - means that no property is applied to the spring or logging system

1

There are 1 best solutions below

0
Peter Szanto On

Try using SpringBoot. In spring boot application.properties is read by default and you don't even need to use @PropertySource to read it. You can download a spring boot application skeleton from https://start.spring.io/