-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mehmet.ari
committed
May 10, 2021
1 parent
3342ff7
commit 4307179
Showing
10 changed files
with
78 additions
and
12 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
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
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
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
50 changes: 50 additions & 0 deletions
50
...is-starter/src/main/java/com/trendyol/jdempotent/redis/RedisEnvironmentPostProcessor.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.trendyol.jdempotent.redis; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.env.EnvironmentPostProcessor; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.MapPropertySource; | ||
import org.springframework.core.env.MutablePropertySources; | ||
import org.springframework.core.env.PropertySource; | ||
|
||
@ConditionalOnProperty( | ||
prefix="jdempotent", name = "enable", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
public class RedisEnvironmentPostProcessor implements EnvironmentPostProcessor { | ||
private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; | ||
|
||
@Override | ||
public void postProcessEnvironment(ConfigurableEnvironment environment, | ||
SpringApplication application) { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("spring.data.redis.repositories.enabled", "false"); | ||
addOrReplace(environment.getPropertySources(), map); | ||
} | ||
|
||
private void addOrReplace(MutablePropertySources propertySources, | ||
Map<String, Object> map) { | ||
MapPropertySource target = null; | ||
if (propertySources.contains(PROPERTY_SOURCE_NAME)) { | ||
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME); | ||
if (source instanceof MapPropertySource) { | ||
target = (MapPropertySource) source; | ||
for (String key : map.keySet()) { | ||
if (!target.containsProperty(key)) { | ||
target.getSource().put(key, map.get(key)); | ||
} | ||
} | ||
} | ||
} | ||
if (target == null) { | ||
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); | ||
} | ||
if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { | ||
propertySources.addLast(target); | ||
} | ||
} | ||
} |
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
5 changes: 4 additions & 1 deletion
5
Jdempotent-spring-boot-redis-starter/src/main/resources/META-INF/spring.factories
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,7 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
com.trendyol.jdempotent.redis.ApplicationConfig,\ | ||
com.trendyol.jdempotent.redis.RedisConfigProperties,\ | ||
com.trendyol.jdempotent.redis.RedisSentinelConfiguration | ||
com.trendyol.jdempotent.redis.RedisSentinelConfiguration,\ | ||
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration | ||
org.springframework.boot.env.EnvironmentPostProcessor=\ | ||
com.trendyol.jdempotent.redis.RedisEnvironmentPostProcessor |
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
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
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