How to create a spring boot starter to initialize applications.properties - spring-boot

How can I create a Spring Boot starter to initialize properties automatically instead of adding them on the application.properties of the application?
For example, the configuration below would be done in the starter, not in the application:
server.port=8443
server.ssl.enabled=true
The common usage of starters is to create beans based on some condition. I just need the starter to define default properties and spring would create the beans.
The idea is to have a common set of properties to be used by many projects, just adding the starter as a dependency.

Related

#ConfigurationProperties in spring boot WAR project

I want to use #ConfigurationProperties and bind some properties in application.properties to that class. When I exclude embedded tomcat dependency from pom.xml, I cant use those properties defined in #ConfigurationProperties class. How can I solve the problem when using an external tomcat?

Load beans/controller from external jar in spring boot without changing config class

I want to load a bean from a external jar into spring boot project. But I don't want to make changes to existing spring boot config file. I want same behavior like actuator. Just add dependency and bean or endpoint will be available in spring boot

Spring Boot - configure properties of a jar included as dependency into another jar

I have a Spring Boot web app A and its dependent on a Spring Boot jar library B. I have some properties that I want to configure within B and don't want the client apps (e.g. the web app A) to configure them. I have these properties files in B.
application-dev.properties
application-stage.properties
applicatino-live.properties
The issue is that these properties are not recognized when the library is added as a dependency in web app A. What is the way to achieve this?
The PropertySource annotation can be used in a Configuration class on webapp A to achieve what you're looking for:
#Configuration
#PropertySource("classpath:application-dev.properties"),
#PropertySource("classpath:application-stage.properties"),
#PropertySource("classpath:application-live.properties")
public class WebappAConfiguration {
}
I also found the order that spring boot looks for externalized configuration helpful here.

How Spring Boot autoconfigures the JCache when there is no JCache configuration file entry in spring.factories file?

I am new to spring boot project.
Currently I am working on a project with spring boot, Jcache with ehcache implementation.
I am trying to understand how spring boot autoconfigures the Cache Framework. I did my own research and identified spring boot #EnableAutoConfiguration reads the spring.factories file and autoconfigures the Cache related beans based on the classes available in classpath.
Here is the Spring Boot Cache auto configure Java based Configuration file available under spring.factories file
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
but for Jcache “ JCacheCacheConfiguration.java” is the Spring Boot auto configuration file , But this file is not available under spring.factroies file in autoconfigurer.jar file.
Then how spring boot auto configures the Jcache without entry in spring.factories file?
JCache implementations are providing a service (in META-INF). So Spring can found the implementation magically. The simpler is #EnableCaching which will find the provider and give you caching right away.
Then, you will want to provide a specific caching configuration. The easiest is by specifying spring.cache.jcache.config=ehcache.xml in your application.properties.
That's it. You will find a more complicated and Java (no xml) configuration in ehcache sample and pet clinic.

spring boot application.yml properties change at runtime

In a spring boot application, I am able to bind properties from application.yml to the bean fields using #ConfigurationProperties annotation.
Is it possible to update these properties in application.yml at runtime and get them reflected in the bean? If yes. How to do this?
In the past, I've gotten this working using ReloadableResourceBundleMessageSource
Spring Cloud Config does that and more. In particular, check the sample application.

Resources