Skip to content

Commit e4f962d

Browse files
authored
refurbish Spring Boot and Togglz article (#100)
1 parent 0f6586d commit e4f962d

File tree

11 files changed

+133
-60
lines changed

11 files changed

+133
-60
lines changed

buildJdk17Projects.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare -a arr=(
1515
"spring-websocket-integration-tests"
1616
"spring-boot-test-mockmvc-webtestclient-testresttemplate"
1717
"random-data-in-java-using-java-faker"
18+
"spring-boot-feature-toggles-with-togglz"
1819
)
1920

2021
for project in "${arr[@]}"
Binary file not shown.
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Codebase for the blog post [Feature Toggles for Spring Boot applications with Togglz](https://rieckpil.de/howto-feature-toggles-for-spring-boot-applications-with-togglz/)
1+
# Codebase for the blog post [Feature Toggles for Spring Boot Applications with Togglz](https://rieckpil.de/howto-feature-toggles-for-spring-boot-applications-with-togglz/)
22

33
Steps to run this project:
44

55
1. Clone this Git repository
66
2. Navigate to the folder `spring-boot-feature-toggles-with-togglz`
7-
3. Start the project with `mvn spring-boot:run`
7+
3. Start the project with `./mvnw spring-boot:run`
88
4. Access both http://localhost:8080/books and http://localhost:8080/books/wishlist
9-
5. Change the state of a feature toggle at http://localhost:8082/togglz-console and re-visit the previous endpoints
9+
5. Change the state of a feature toggle at http://localhost:8082/togglz-console and re-visit the previous endpoints

spring-boot-feature-toggles-with-togglz/mvnw

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# "License"); you may not use this file except in compliance
99
# with the License. You may obtain a copy of the License at
1010
#
11-
# https://www.apache.org/licenses/LICENSE-2.0
11+
# http://www.apache.org/licenses/LICENSE-2.0
1212
#
1313
# Unless required by applicable law or agreed to in writing,
1414
# software distributed under the License is distributed on an
@@ -19,7 +19,7 @@
1919
# ----------------------------------------------------------------------------
2020

2121
# ----------------------------------------------------------------------------
22-
# Maven2 Start Up Batch script
22+
# Maven Start Up Batch script
2323
#
2424
# Required ENV vars:
2525
# ------------------
@@ -36,6 +36,10 @@
3636

3737
if [ -z "$MAVEN_SKIP_RC" ] ; then
3838

39+
if [ -f /usr/local/etc/mavenrc ] ; then
40+
. /usr/local/etc/mavenrc
41+
fi
42+
3943
if [ -f /etc/mavenrc ] ; then
4044
. /etc/mavenrc
4145
fi
@@ -114,7 +118,6 @@ if $mingw ; then
114118
M2_HOME="`(cd "$M2_HOME"; pwd)`"
115119
[ -n "$JAVA_HOME" ] &&
116120
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117-
# TODO classpath?
118121
fi
119122

120123
if [ -z "$JAVA_HOME" ]; then
@@ -146,7 +149,7 @@ if [ -z "$JAVACMD" ] ; then
146149
JAVACMD="$JAVA_HOME/bin/java"
147150
fi
148151
else
149-
JAVACMD="`which java`"
152+
JAVACMD="`\\unset -f command; \\command -v java`"
150153
fi
151154
fi
152155

@@ -212,7 +215,11 @@ else
212215
if [ "$MVNW_VERBOSE" = true ]; then
213216
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214217
fi
215-
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
218+
if [ -n "$MVNW_REPOURL" ]; then
219+
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
220+
else
221+
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
222+
fi
216223
while IFS="=" read key value; do
217224
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218225
esac
@@ -221,22 +228,38 @@ else
221228
echo "Downloading from: $jarUrl"
222229
fi
223230
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
231+
if $cygwin; then
232+
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
233+
fi
224234

225235
if command -v wget > /dev/null; then
226236
if [ "$MVNW_VERBOSE" = true ]; then
227237
echo "Found wget ... using wget"
228238
fi
229-
wget "$jarUrl" -O "$wrapperJarPath"
239+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
240+
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241+
else
242+
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
243+
fi
230244
elif command -v curl > /dev/null; then
231245
if [ "$MVNW_VERBOSE" = true ]; then
232246
echo "Found curl ... using curl"
233247
fi
234-
curl -o "$wrapperJarPath" "$jarUrl"
248+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
249+
curl -o "$wrapperJarPath" "$jarUrl" -f
250+
else
251+
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
252+
fi
253+
235254
else
236255
if [ "$MVNW_VERBOSE" = true ]; then
237256
echo "Falling back to using Java to download"
238257
fi
239258
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
259+
# For Cygwin, switch paths to Windows format before running javac
260+
if $cygwin; then
261+
javaClass=`cygpath --path --windows "$javaClass"`
262+
fi
240263
if [ -e "$javaClass" ]; then
241264
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242265
if [ "$MVNW_VERBOSE" = true ]; then
@@ -277,10 +300,17 @@ if $cygwin; then
277300
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278301
fi
279302

303+
# Provide a "standardized" way to retrieve the CLI args that will
304+
# work with both Windows and non-Windows executions.
305+
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
306+
export MAVEN_CMD_LINE_ARGS
307+
280308
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281309

282310
exec "$JAVACMD" \
283311
$MAVEN_OPTS \
312+
$MAVEN_DEBUG_OPTS \
284313
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285-
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
314+
"-Dmaven.home=${M2_HOME}" \
315+
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286316
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

spring-boot-feature-toggles-with-togglz/mvnw.cmd

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@REM "License"); you may not use this file except in compliance
88
@REM with the License. You may obtain a copy of the License at
99
@REM
10-
@REM https://www.apache.org/licenses/LICENSE-2.0
10+
@REM http://www.apache.org/licenses/LICENSE-2.0
1111
@REM
1212
@REM Unless required by applicable law or agreed to in writing,
1313
@REM software distributed under the License is distributed on an
@@ -18,15 +18,15 @@
1818
@REM ----------------------------------------------------------------------------
1919

2020
@REM ----------------------------------------------------------------------------
21-
@REM Maven2 Start Up Batch script
21+
@REM Maven Start Up Batch script
2222
@REM
2323
@REM Required ENV vars:
2424
@REM JAVA_HOME - location of a JDK home dir
2525
@REM
2626
@REM Optional ENV vars
2727
@REM M2_HOME - location of maven2's installed home dir
2828
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29-
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
29+
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
3030
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
3131
@REM e.g. to debug Maven itself, use
3232
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@@ -37,7 +37,7 @@
3737
@echo off
3838
@REM set title of command window
3939
title %0
40-
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
40+
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
4141
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
4242

4343
@REM set %HOME% to equivalent of $HOME
@@ -46,8 +46,8 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
4646
@REM Execute a user defined script before this one
4747
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
4848
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
49-
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50-
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49+
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
50+
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
5151
:skipRcPre
5252

5353
@setlocal
@@ -120,24 +120,51 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120120
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121121
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122122

123-
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124-
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125-
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
123+
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
124+
125+
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126+
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126127
)
127128

128129
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129130
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130131
if exist %WRAPPER_JAR% (
131-
echo Found %WRAPPER_JAR%
132+
if "%MVNW_VERBOSE%" == "true" (
133+
echo Found %WRAPPER_JAR%
134+
)
132135
) else (
133-
echo Couldn't find %WRAPPER_JAR%, downloading it ...
134-
echo Downloading from: %DOWNLOAD_URL%
135-
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136-
echo Finished downloading %WRAPPER_JAR%
136+
if not "%MVNW_REPOURL%" == "" (
137+
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
138+
)
139+
if "%MVNW_VERBOSE%" == "true" (
140+
echo Couldn't find %WRAPPER_JAR%, downloading it ...
141+
echo Downloading from: %DOWNLOAD_URL%
142+
)
143+
144+
powershell -Command "&{"^
145+
"$webclient = new-object System.Net.WebClient;"^
146+
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147+
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148+
"}"^
149+
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150+
"}"
151+
if "%MVNW_VERBOSE%" == "true" (
152+
echo Finished downloading %WRAPPER_JAR%
153+
)
137154
)
138155
@REM End of extension
139156

140-
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
157+
@REM Provide a "standardized" way to retrieve the CLI args that will
158+
@REM work with both Windows and non-Windows executions.
159+
set MAVEN_CMD_LINE_ARGS=%*
160+
161+
%MAVEN_JAVA_EXE% ^
162+
%JVM_CONFIG_MAVEN_PROPS% ^
163+
%MAVEN_OPTS% ^
164+
%MAVEN_DEBUG_OPTS% ^
165+
-classpath %WRAPPER_JAR% ^
166+
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
167+
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141168
if ERRORLEVEL 1 goto error
142169
goto end
143170

@@ -147,15 +174,15 @@ set ERROR_CODE=1
147174
:end
148175
@endlocal & set ERROR_CODE=%ERROR_CODE%
149176

150-
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
177+
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
151178
@REM check for post script, once with legacy .bat ending and once with .cmd ending
152-
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153-
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
179+
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
180+
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
154181
:skipRcPost
155182

156183
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157-
if "%MAVEN_BATCH_PAUSE%" == "on" pause
184+
if "%MAVEN_BATCH_PAUSE%"=="on" pause
158185

159-
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
186+
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
160187

161-
exit /B %ERROR_CODE%
188+
cmd /C exit /B %ERROR_CODE%

spring-boot-feature-toggles-with-togglz/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5+
56
<parent>
67
<groupId>org.springframework.boot</groupId>
78
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.3.0.RELEASE</version>
9+
<version>2.7.0</version>
910
<relativePath/> <!-- lookup parent from repository -->
1011
</parent>
12+
1113
<groupId>de.rieckpil.blog</groupId>
1214
<artifactId>spring-boot-feature-toggles-with-togglz</artifactId>
1315
<version>0.0.1-SNAPSHOT</version>
1416
<name>spring-boot-feature-toggles-with-togglz</name>
1517
<description>Demo project for Spring Boot with Togglz</description>
1618

1719
<properties>
18-
<java.version>11</java.version>
19-
<togglz.version>2.6.1.Final</togglz.version>
20+
<java.version>17</java.version>
21+
<togglz.version>3.2.1</togglz.version>
2022
</properties>
2123

2224
<dependencies>
@@ -56,5 +58,4 @@
5658
</plugin>
5759
</plugins>
5860
</build>
59-
6061
</project>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class SpringBootFeatureTogglesWithTogglzApplication {
7+
public class Application {
88

99
public static void main(String[] args) {
10-
SpringApplication.run(SpringBootFeatureTogglesWithTogglzApplication.class, args);
10+
SpringApplication.run(Application.class, args);
1111
}
1212

1313
}

spring-boot-feature-toggles-with-togglz/src/main/java/de/rieckpil/blog/BookController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.node.ArrayNode;
66
import com.fasterxml.jackson.databind.node.ObjectNode;
7-
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.http.ResponseEntity;
98
import org.springframework.web.bind.annotation.GetMapping;
109
import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,11 +17,13 @@
1817
@RequestMapping("/books")
1918
public class BookController {
2019

21-
@Autowired
22-
private FeatureManager featureManager;
20+
private final FeatureManager featureManager;
21+
private final ObjectMapper objectMapper;
2322

24-
@Autowired
25-
private ObjectMapper objectMapper;
23+
public BookController(FeatureManager featureManager, ObjectMapper objectMapper) {
24+
this.featureManager = featureManager;
25+
this.objectMapper = objectMapper;
26+
}
2627

2728
@GetMapping
2829
public ResponseEntity<JsonNode> getBook() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.rieckpil.blog;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class ApplicationTest {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
}

spring-boot-feature-toggles-with-togglz/src/test/java/de/rieckpil/blog/SpringBootFeatureTogglesWithTogglzApplicationTests.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)