Browse Source

修复属性注入

赵冬冬 4 years ago
parent
commit
6640cab3c3

+ 11 - 10
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/config/redis/RedissonConfig.java

@@ -4,30 +4,31 @@ import org.redisson.Redisson;
 import org.redisson.api.RedissonClient;
 import org.redisson.config.Config;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.core.env.Environment;
 
 /**
  * redisson通用化配置
  **/
 @Configuration
+@EnableConfigurationProperties(RedissonProperties.class)
 public class RedissonConfig {
-    @Autowired
-    private Environment env;
 
-    @Value("${myredis.address}")
-    private String address;
-    @Value("${myredis.passord}")
-    private String password;
+
+    private RedissonProperties properties;
+
+    @Autowired
+    public RedissonConfig(RedissonProperties properties) {
+        this.properties = properties;
+    }
 
     @Bean
     public RedissonClient redissonClient() {
         Config config = new Config();
         config.useSingleServer()
-                .setAddress(address)
-                .setPassword(password);
+                .setAddress(properties.getAddress())
+                .setPassword(properties.getPassword());
         RedissonClient client = Redisson.create(config);
         return client;
     }

+ 12 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/config/redis/RedissonProperties.java

@@ -0,0 +1,12 @@
+package com.hcloud.microserver.h5.config.redis;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@Data
+@ConfigurationProperties(prefix = "myredis")
+public class RedissonProperties {
+    private String address;
+
+    private String password;
+}

+ 1 - 4
carbon-h5/carbon-h5-service/src/main/resources/bootstrap.yml

@@ -19,7 +19,4 @@ spring:
         prefix: carbon-h5
         file-extension: yml
         # 公共配置文件
-        shared-dataids: carbon-common.yml
-myredis:
-  address: redis://${spring.redis.host}:${spring.redis.port}
-  passord: ${spring.redis.password}
+        shared-dataids: carbon-common.yml

File diff suppressed because it is too large
+ 1379 - 0
postman/zdd/重庆碳汇.postman_collection.json