Browse Source

Implement support for additional properties files

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.3-alpha
Pekka Helenius 4 years ago
parent
commit
978ddb2806
4 changed files with 113 additions and 0 deletions
  1. +69
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/config/AdditionalPropertiesConfig.java
  2. +3
    -0
      bookstore/src/main/resources/META-INF/spring.factories
  3. +4
    -0
      bookstore/src/main/resources/authentication.properties
  4. +37
    -0
      bookstore/src/main/resources/website.properties

+ 69
- 0
bookstore/src/main/java/com/fjordtek/bookstore/config/AdditionalPropertiesConfig.java View File

@ -0,0 +1,69 @@
//Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020
package com.fjordtek.bookstore.config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
/**
*
* This class implements a custom EnvironmentPostProcessor interface.
* <p>
* Main purpose of this implementation is to load additional properties files into Spring
* environment as early as possible during Spring Boot initialization process.
* <p>
* Loading of this class must be enabled in /resources/META-INF/spring.factories file.
*
* @author Pekka Helenius
*/
@Configuration
//@Order(Ordered.LOWEST_PRECEDENCE)
public class AdditionalPropertiesConfig implements EnvironmentPostProcessor {
private List<Resource> getAdditionalResources() {
List<Resource> resources = new ArrayList<Resource>();
// Add your additional properties files here
resources.add(new ClassPathResource("website.properties"));
resources.add(new ClassPathResource("authentication.properties"));
return resources;
}
@Override
public void postProcessEnvironment(
ConfigurableEnvironment environment,
SpringApplication application
) {
MutablePropertySources propertySources = environment.getPropertySources();
for (Resource res : getAdditionalResources()) {
try {
propertySources.addLast(
new PropertiesPropertySource(
res.getFilename(),
PropertiesLoaderUtils.loadProperties(res)
)
);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

+ 3
- 0
bookstore/src/main/resources/META-INF/spring.factories View File

@ -0,0 +1,3 @@
# Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020
org.springframework.boot.env.EnvironmentPostProcessor = com.fjordtek.bookstore.config.AdditionalPropertiesConfig

+ 4
- 0
bookstore/src/main/resources/authentication.properties View File

@ -0,0 +1,4 @@
# Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020
auth.field.username = b_username
auth.field.password = b_password

+ 37
- 0
bookstore/src/main/resources/website.properties View File

@ -0,0 +1,37 @@
# Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020
# BookController
# Public end points
#
page.url.index = /
page.url.login = /login
page.url.logout = /logout
page.url.list = /booklist
page.url.add = /bookadd
page.url.edit = /bookedit
page.url.delete = /bookdelete
page.url.apiref = /apiref
page.url.autherror = /autherror
page.url.error = /error
# BookRestController
# Public JSON end points
#
page.url.json = /json
page.url.json.list = ${page.url.list}
page.url.json.book = /book
# BookBasePathAwareController
# Native REST API end points
#
page.url.restapi.list = /${page.url.list}
# Bookstore assets & resources
#
page.url.resources.css = /css
page.url.resources.js = /js
page.url.resources.images = /images

Loading…
Cancel
Save