-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔇 silent changes: add resolve placeholders by configs for SagaAuthHea…
…der annotation #2
- Loading branch information
1 parent
426bd45
commit 852cf97
Showing
3 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
plugin/src/main/groovy/org/clarify4j/service/Clarify4jService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package org.clarify4j.service; | ||
|
||
public interface Clarify4jService { | ||
|
||
String resolveValue(String value); | ||
} |
37 changes: 36 additions & 1 deletion
37
plugin/src/main/groovy/org/clarify4j/service/impl/Clarify4jServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
package org.clarify4j.service.impl; | ||
|
||
import org.clarify4j.service.Clarify4jService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
import org.clarify4j.service.Clarify4jService; | ||
import org.unify4j.common.String4j; | ||
|
||
@SuppressWarnings({"FieldCanBeLocal", "DuplicatedCode"}) | ||
@Service | ||
public class Clarify4jServiceImpl implements Clarify4jService { | ||
protected static final Logger logger = LoggerFactory.getLogger(Clarify4jServiceImpl.class); | ||
|
||
protected final Environment environment; | ||
|
||
@Autowired | ||
public Clarify4jServiceImpl(Environment environment) { | ||
this.environment = environment; | ||
} | ||
|
||
/** | ||
* Resolves placeholders in a given string value using Spring's environment property resolution. | ||
* <p> | ||
* This method checks if the provided value string contains placeholders in the format of | ||
* "${property.name}". If it does, the method uses Spring's `Environment` to resolve these | ||
* placeholders to their actual values from the application's property sources (such as | ||
* application.yml or application.properties). If the value does not contain placeholders, | ||
* it is returned as-is. | ||
* | ||
* @param value The string value to be resolved. This can be a literal string or a string | ||
* containing placeholders. | ||
* @return The resolved value if it contains placeholders, or the original value if no | ||
* placeholders are present. | ||
*/ | ||
@Override | ||
public String resolveValue(String value) { | ||
if (String4j.isEmpty(value)) { | ||
return value; | ||
} | ||
if (value.startsWith("${") && value.endsWith("}")) { | ||
return environment.resolvePlaceholders(value); | ||
} | ||
return value; | ||
} | ||
} |