0

Create custom Spring boot starter my-spring-boot-starter from spring-boot-starter-parent.
In source folder of my Starter add applicatin.property file that contains property to config logging:

logging.pattern.console=<custom pattern>

Then add my starter to my spring boot application dependency, but for some reason logging pattern do not change to my from starter. How to describe spring boot property to override in my custom starter (like logging property or default port property) ?

Alstresh
  • 583
  • 2
  • 4
  • 16
  • The file needs to be spelled correctly, `application.properties` – Matt Dec 24 '18 at 14:47
  • Also could you clarify what you mean by "add my starter to my spring boot application dependency" - are you putting the config file in a separate project and then including that project in another project? Why not just put it directly in the project you want to configure? – Matt Dec 24 '18 at 14:49

1 Answers1

4

You can't change application configuration like this. The environment is made of a set of PropertySource instances, each describing a source for configuration. The list and the precedence are documented in the user guide.

Regarding application.properties at the root of the classpath, you can't use that in a starter as this is a very typical location for application's configuration: as soon as the user create a file in the project, it will take precedence to the one you've defined in the starter.

If you want to manipulate the environment in your starter, you need to implement an EnvironmentPostProcessor and add a custom PropertySource in the Environment. This is also described in the documentation.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89