io.github.topikachu:propertysource-reload

propertysource reload parent

Лицензия

Лицензия

Группа

Группа

io.github.topikachu
Идентификатор

Идентификатор

propertysource-reload
Последняя версия

Последняя версия

0.0.7
Дата

Дата

Тип

Тип

pom
Описание

Описание

io.github.topikachu:propertysource-reload
propertysource reload parent
Ссылка на сайт

Ссылка на сайт

https://github.com/topikachu/spring-propertysource-reload
Организация-разработчик

Организация-разработчик

Pivotal Software, Inc.
Система контроля версий

Система контроля версий

https://github.com/topikachu/spring-propertysource-reload/tree/master

Скачать propertysource-reload

Имя Файла Размер
propertysource-reload-0.0.7.pom 10 KB
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.github.topikachu/propertysource-reload/ -->
<dependency>
    <groupId>io.github.topikachu</groupId>
    <artifactId>propertysource-reload</artifactId>
    <version>0.0.7</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.topikachu/propertysource-reload/
implementation 'io.github.topikachu:propertysource-reload:0.0.7'
// https://jarcasting.com/artifacts/io.github.topikachu/propertysource-reload/
implementation ("io.github.topikachu:propertysource-reload:0.0.7")
'io.github.topikachu:propertysource-reload:pom:0.0.7'
<dependency org="io.github.topikachu" name="propertysource-reload" rev="0.0.7">
  <artifact name="propertysource-reload" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.topikachu', module='propertysource-reload', version='0.0.7')
)
libraryDependencies += "io.github.topikachu" % "propertysource-reload" % "0.0.7"
[io.github.topikachu/propertysource-reload "0.0.7"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

  • propertysource-reload-spring-boot-starter

PropertySource Reload Spring Framework Boot Starters

Java CI with Maven

Table of Contents

Usage

This starter can auto detect the external property source (current only support java properties file) change on the file system, and triggers the refresh process of the application.

Repository

Repository contains:

  • propertysource-reload-spring-boot-starter the starter project which enables propertysource reload
  • propertysource-reload-example an example demonstrating the usage of the starter

Requirements and Downloads

Requirements:

  • Java 1.8
  • Spring Framework Boot > 2.x.x

Gradle:

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
  implementation 'io.github.topikachu:propertysource-reload-spring-boot-starter:0.0.7'
}

Maven:

<dependency>
    <groupId>io.github.topikachu</groupId>
    <artifactId>propertysource-reload-spring-boot-starter</artifactId>
    <version>0.0.7</version>
</dependency>

This starter requires the Spring Cloud Context . Add at least one Spring Cloud module, for example:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter</artifactId>
</dependency>

How to enable external property source reloading

  1. Use annotation at class level
    @ReloadablePropertySource({ "config/a.properties", "config/b.properties" }) The starter only scans the packages same as or sub of the application's. It's NOT aware of @ComponentScan
  2. Specify the configuration file in the bootstrap.properties or bootstrap.yaml:
    propertysource.reload.properties-files=config/foo.properties,config/bar.properties

Spring Boot bootstrap configuration parameter:

propertysource.reload.properties-files=
propertysource.reload.poll-interval=5s
propertysource.reload.strategy=refresh_environment
propertysource.reload.max-wait-for-shutdown=2s
propertysource.reload.max-wait-for-system-exit=10s
propertysource.reload.ignore-resource-not-found=true
propertysource.reload.ignore-resource-load-error=true

Once the content of the configuration file specified in propertysource.reload.properties-files is change, the application is reload automatically.

Reload Strategy

  1. refresh_scope
    This is the default strategy. Execute ContextRefresher.refresh().
  2. refresh_environment
    Execute ContextRefresher.refreshEnvironment().
  3. exit_application
    Execute SpringApplication.exit()
  4. exit_application_force
    Execute SpringApplication.exit() and System.exit()
  5. restart
    Set management.endpoint.restart.enabled=true to enable this strategy. See RestartEndpoint#restart for details.

PropertySourceReloadEvent

There's a PropertySourceReloadEvent fired after each reload. To receive this event

	@EventListener(PropertySourceReloadEvent.class)
	public void onRefresh(PropertySourceReloadEvent event) {
		System.out.println(String.join(",", event.getKeys()));
		System.out.println(event.getFile().getName());
		System.out.println(event.getFileEvent());
	}

Environment Changes

Please read spring documentation for detail.
In a short description, the @ConfigurationProperties beans are rebind, but @Value are not by default. Any bean using @Value to inject the configuration must use @RefreshScope to receive the new change.

Delete Configuration at Runtime

It's very difficult to handle the configuration deletion. Try to always keep the keys at runtime. Another solution is to use "@RefreshScope" at any bean depending on the configuration may change during runtime.

Contributions

Contributions are welcome. Please respect the Code of Conduct.

Licenses

propertysource-reload-spring-boot-starter are licensed under the Apache 2.0 License. See LICENSE for details.

Версии библиотеки

Версия
0.0.7
0.0.6
0.0.4