Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize SpringBoot2 dynamic @ Value

Shulou Source: shulou.com Published: 2022-06-01 01:30:44 10月02日 Update

< strVal.length() - 1) { String remainingPart = normalizeToPlaceholder(strVal.substring(endIndex + PLACEHOLDER_SUFFIX.length())); if (!Strings.isNullOrEmpty(remainingPart)) { stack.push(remainingPart); } } } return placeholderKeys; } private boolean isNormalizedPlaceholder(String propertyString) { return propertyString.startsWith(PLACEHOLDER_PREFIX) && propertyString.endsWith(PLACEHOLDER_SUFFIX); } private boolean isExpressionWithPlaceholder(String propertyString) { return propertyString.startsWith(EXPRESSION_PREFIX) && propertyString.endsWith(EXPRESSION_SUFFIX) && propertyString.contains(PLACEHOLDER_PREFIX); } private String normalizeToPlaceholder(String strVal) { int startIndex = strVal.indexOf(PLACEHOLDER_PREFIX); if (startIndex == -1) { return null; } int endIndex = strVal.lastIndexOf(PLACEHOLDER_SUFFIX); if (endIndex == -1) { return null; } return strVal.substring(startIndex, endIndex + PLACEHOLDER_SUFFIX.length()); } private int findPlaceholderEndIndex(CharSequence buf, int startIndex) { int index = startIndex + PLACEHOLDER_PREFIX.length(); int withinNestedPlaceholder = 0; while (index < buf.length()) { if (StringUtils.substringMatch(buf, index, PLACEHOLDER_SUFFIX)) { if (withinNestedPlaceholder >

0) {withinNestedPlaceholder--; index = index+ PLACEHOLDER_SUFFIX.length ();} else {return index;}} else if (StringUtils.substringMatch (buf, index, SIMPLE_PLACEHOLDER_PREFIX)) {withinNestedPlaceholder++; index = index+ SIMPLE_PLACEHOLDER_PREFIX.length ();} else {index++;}} return-1 }} package com.allen.apollo;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Value;import org.springframework.util.StringUtils;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;import java.lang.reflect.InvocationTargetException;@RestController@Slf4jpublic class SpringValueController {@ Value ("${test:123}") public String zax; @ Value ("${test:123}") public String test @ Value (("${zed:zed}")) public String zed; @ GetMapping ("/ test") public String test (String a, String b) {if (! StringUtils.isEmpty (a)) {try {for (SpringValue springValue: SpringValueCacheMap.map.get ("test")) {springValue.update (a) } for (SpringValue springValue: SpringValueCacheMap.map.get ("zed")) {springValue.update (b);}} catch (IllegalAccessException | InvocationTargetException e) {e.printStackTrace () }} return String.format ("test:% s, zax:% s, zed:% s", test, zax, zed);}} "how to implement SpringBoot2 dynamic @ Value" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Dynamic code e.g. storage content fields examples more knowledge practicality learning and then functions just dilemmas realities situations interfaces articles cases. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Xiaomi MySQL Shulou Tech Info