Added Spring example.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/9c8e3581 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/9c8e3581 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/9c8e3581 Branch: refs/heads/master Commit: 9c8e3581c98cb0d6663807b2b0e446fbd4345c6d Parents: 7c071ca Author: Anatole Tresch <[email protected]> Authored: Sun Nov 19 23:22:26 2017 +0100 Committer: Anatole Tresch <[email protected]> Committed: Sun Nov 19 23:23:42 2017 +0100 ---------------------------------------------------------------------- examples/05-spring-example/pom.xml | 128 +++++++++++++++++++ .../SampleWebFreeMarkerApplication.java | 31 +++++ .../tamaya/springexample/WelcomeController.java | 50 ++++++++ .../META-INF/javaconfiguration.properties | 21 +++ .../src/main/resources/templates/error.ftl | 26 ++++ .../src/main/resources/templates/welcome.ftl | 32 +++++ examples/pom.xml | 1 + 7 files changed, 289 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/pom.xml ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/pom.xml b/examples/05-spring-example/pom.xml new file mode 100644 index 0000000..93c600c --- /dev/null +++ b/examples/05-spring-example/pom.xml @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>1.5.6.RELEASE</version> + </parent> + + <artifactId>05-spring-example</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + + <properties> + <spring.version>4.3.10.RELEASE</spring.version> + <spring.boot.version>1.5.8.RELEASE</spring.boot.version> + <tamaya-apicore.version>0.4-incubating-SNAPSHOT</tamaya-apicore.version> + </properties> + + <name>Apache Tamaya Spring Example</name> + + <description> + This project contains a simple example demonstrating the usage + of the Tamaya Spring module. + </description> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> + <!--<dependency>--> + <!--<groupId>org.apache.tamaya.ext</groupId>--> + <!--<artifactId>tamaya-mutable-config</artifactId>--> + <!--<version>${tamaya-apicore.version}</version>--> + <!--</dependency>--> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${tamaya-apicore.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-events</artifactId> + <version>${project.version}</version> + </dependency> + <!--<dependency>--> + <!--<groupId>org.apache.tamaya.ext</groupId>--> + <!--<artifactId>tamaya-etcd_beta</artifactId>--> + <!--<version>${project.version}</version>--> + <!--</dependency>--> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-spring</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-injection</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.pitest</groupId> + <artifactId>pitest-maven</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/SampleWebFreeMarkerApplication.java ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/SampleWebFreeMarkerApplication.java b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/SampleWebFreeMarkerApplication.java new file mode 100644 index 0000000..3092a1d --- /dev/null +++ b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/SampleWebFreeMarkerApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tamaya.springexample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + + +@SpringBootApplication +@ComponentScan({"org.apache.tamaya.integration.spring", "org.apache.tamaya.springexample"}) +public class SampleWebFreeMarkerApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleWebFreeMarkerApplication.class, args); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java new file mode 100644 index 0000000..bbe921f --- /dev/null +++ b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tamaya.springexample; + +import java.util.Date; +import java.util.Map; + +import org.apache.tamaya.inject.api.Config; +import org.apache.tamaya.inject.api.DynamicValue; +import org.apache.tamaya.inject.api.UpdatePolicy; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @Config(value = "background.color", required = false) + private String backgroundColor = "#BBBBBB"; + + @Config(value = "foreground.color", required = false, defaultValue = "#DDDDDD") + private DynamicValue<String> foregroundColor; + + @GetMapping("/") + public String welcome(Map<String, Object> model) { + foregroundColor.setUpdatePolicy(UpdatePolicy.IMMEDIATE); + model.put("time", new Date()); + model.put("message", this.message); + model.put("background", this.backgroundColor); + model.put("foreground", this.foregroundColor.get()); + return "welcome"; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/src/main/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/src/main/resources/META-INF/javaconfiguration.properties b/examples/05-spring-example/src/main/resources/META-INF/javaconfiguration.properties new file mode 100644 index 0000000..b2d9136 --- /dev/null +++ b/examples/05-spring-example/src/main/resources/META-INF/javaconfiguration.properties @@ -0,0 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +application.message=Hallo by Tamaya! +background.color=#123456 +foreground.color=#FFDDDD \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/src/main/resources/templates/error.ftl ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/src/main/resources/templates/error.ftl b/examples/05-spring-example/src/main/resources/templates/error.ftl new file mode 100644 index 0000000..808cc91 --- /dev/null +++ b/examples/05-spring-example/src/main/resources/templates/error.ftl @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<!-- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +--> +<html lang="en"> + +<body> + Something went wrong: ${status} ${error} +</body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/05-spring-example/src/main/resources/templates/welcome.ftl ---------------------------------------------------------------------- diff --git a/examples/05-spring-example/src/main/resources/templates/welcome.ftl b/examples/05-spring-example/src/main/resources/templates/welcome.ftl new file mode 100644 index 0000000..696e4bc --- /dev/null +++ b/examples/05-spring-example/src/main/resources/templates/welcome.ftl @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<!-- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +--> +<html lang="en"> + +<body bgcolor="${background}"> + <font color="${foreground}}"> + Date: ${time?date} + <br> + Time: ${time?time} + <br> + Message: ${message} + </font> +</body> + +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9c8e3581/examples/pom.xml ---------------------------------------------------------------------- diff --git a/examples/pom.xml b/examples/pom.xml index 7a1c73f..0023a0f 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -41,6 +41,7 @@ under the License. <module>02-resolver-example</module> <module>03-injection-example</module> <module>04-events-example</module> + <module>05-spring-example</module> </modules> </project> \ No newline at end of file
