From ff2b8e50257d02b0d49f00612ea7f84c670b6fe4 Mon Sep 17 00:00:00 2001 From: Frank Bregulla Date: Tue, 28 Mar 2017 11:19:23 +0200 Subject: [PATCH] Add spring properties bean for properties. --- README.md | 7 +++++++ build.gradle | 8 +++++-- .../esidialect/EsiDialectConfiguration.java | 7 ++++--- .../otto/esidialect/EsiDialectProperties.java | 21 +++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/otto/esidialect/EsiDialectProperties.java diff --git a/README.md b/README.md index 98a27a0..c6f3af2 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,13 @@ When spring profiles "local" or "prod" are active, esi-includes will be resolved # 3. Release Notes +## Version 0.0.4 +* Add spring properties bean for property `esiinclude-thymeleaf-dialect.prefixForRelativePath` +so that you get syntax highlighting and code completion in your application*.yml files in your IDE. + + This property may now also be written "`prefix-for-relative-path`" + + ## Version 0.0.3 * Add javadoc * Rename variables and httpClient to Fetch diff --git a/build.gradle b/build.gradle index 02f71f5..bc53a8b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'signing' apply plugin: 'com.github.ben-manes.versions' group = 'de.otto' -version = '0.0.3' +version = '0.0.4' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") archivesBaseName = 'esi-include-thymeleaf3-dialect' @@ -31,18 +31,22 @@ ext.libraries = [ ] dependencies { + ext.springBootVersion = '1.4.2.RELEASE' compileOnly libraries.thymeleaf3 compileOnly group: 'com.ning', name: 'async-http-client', version: '1.9.33' compile group: 'org.springframework', name: 'spring-context', version: '4.3.4.RELEASE' compile group: 'org.springframework', name: 'spring-beans', version: '4.3.4.RELEASE' - compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.4.2.RELEASE' + compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: springBootVersion testCompile group: 'junit', name: 'junit', version: '4.11' testCompile libraries.thymeleaf3 testCompile "org.mockito:mockito-core:1.10.19" testCompile "org.hamcrest:hamcrest-core:1.3" testCompile "org.hamcrest:hamcrest-library:1.3" + + compileOnly "org.springframework.boot:spring-boot-configuration-processor:" + springBootVersion + } // for gradle plugins diff --git a/src/main/java/de/otto/esidialect/EsiDialectConfiguration.java b/src/main/java/de/otto/esidialect/EsiDialectConfiguration.java index a73d901..19d67f5 100644 --- a/src/main/java/de/otto/esidialect/EsiDialectConfiguration.java +++ b/src/main/java/de/otto/esidialect/EsiDialectConfiguration.java @@ -3,10 +3,10 @@ import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClientConfig; import de.otto.esidialect.thymeleaf3.EsiDialect; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -32,6 +32,7 @@ *

*/ @Configuration +@EnableConfigurationProperties(EsiDialectProperties.class) @Profile({"local", "prod"}) public class EsiDialectConfiguration { @@ -63,8 +64,8 @@ public Fetch fetch() { @Bean @ConditionalOnClass(AbstractElementTagProcessor.class) @ConditionalOnMissingBean(EsiDialect.class) - public EsiDialect conditionalEsiDialect(Fetch fetch, @Value("${esiinclude-thymeleaf-dialect.prefixForRelativePath:}") String prefixForRelativePath) { - return new EsiDialect(fetch, prefixForRelativePath); + public EsiDialect conditionalEsiDialect(Fetch fetch, EsiDialectProperties properties) { + return new EsiDialect(fetch, properties.getPrefixForRelativePath()); } } diff --git a/src/main/java/de/otto/esidialect/EsiDialectProperties.java b/src/main/java/de/otto/esidialect/EsiDialectProperties.java new file mode 100644 index 0000000..695b21f --- /dev/null +++ b/src/main/java/de/otto/esidialect/EsiDialectProperties.java @@ -0,0 +1,21 @@ +package de.otto.esidialect; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "esiinclude-thymeleaf-dialect") +public class EsiDialectProperties { + + private String prefixForRelativePath; + + /** + * Optional prefix for relative esi:include paths + * @return prefix for relative esi:include paths or null if not set + */ + public String getPrefixForRelativePath() { + return prefixForRelativePath; + } + + public void setPrefixForRelativePath(String prefixForRelativePath) { + this.prefixForRelativePath = prefixForRelativePath; + } +}