浏览代码

增加配置文件读取

tags/v1.0.0^2
林万龙 3 年前
父节点
当前提交
777127d168
共有 5 个文件被更改,包括 34 次插入6 次删除
  1. +22
    -0
      src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java
  2. +1
    -2
      src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java
  3. +6
    -0
      src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java
  4. +1
    -1
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java
  5. +4
    -3
      src/main/resources/bootstrap.yaml

+ 22
- 0
src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java 查看文件

@@ -0,0 +1,22 @@
package com.telpo.dipperposition.annotation;

import java.lang.annotation.*;

/**
* @program: DataPushServer
* @description: mongo数据源切换注解
* @author: linwl
* @create: 2020-07-11 15:06
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MongoSwitch {

/**
* mongo数据库名称
*
* @return
*/
String value() default "";
}

+ 1
- 2
src/main/java/com/telpo/dipperposition/config/db/MongoDbContext.java 查看文件

@@ -22,8 +22,7 @@ import java.util.Map;
public class MongoDbContext {

private static final Map<String, MongoDbFactory> MONGO_CLIENT_DB_FACTORY_MAP = new HashMap<>();
private static final ThreadLocal<MongoDbFactory> MONGO_DB_FACTORY_THREAD_LOCAL =
new ThreadLocal<>();
private static final ThreadLocal<MongoDbFactory> MONGO_DB_FACTORY_THREAD_LOCAL = new ThreadLocal<>();
@Autowired
MongoListProperties mongoListProperties;



+ 6
- 0
src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java 查看文件

@@ -1,5 +1,6 @@
package com.telpo.dipperposition.mapper;

import com.telpo.dipperposition.annotation.MongoSwitch;
import com.telpo.dipperposition.entity.mongo.IPProvinceEntity;
import db.BaseMongoDbDao;
import org.springframework.stereotype.Repository;
@@ -21,11 +22,13 @@ public class IPProvinceMapper extends BaseMongoDbDao<IPProvinceEntity> {
}

@Override
@MongoSwitch("common")
public void save(IPProvinceEntity entity, String collectionName) {
super.save(entity, collectionName);
}

@Override
@MongoSwitch("common")
public void updateFirst(IPProvinceEntity srcObj, IPProvinceEntity targetObj) {
super.updateFirst(srcObj, targetObj);
}
@@ -36,16 +39,19 @@ public class IPProvinceMapper extends BaseMongoDbDao<IPProvinceEntity> {
}

@Override
@MongoSwitch("common")
public List<IPProvinceEntity> queryList(IPProvinceEntity object) {
return super.queryList(object);
}

@Override
@MongoSwitch("common")
public List<IPProvinceEntity> queryList(IPProvinceEntity object, String collectionName) {
return super.queryList(object, collectionName);
}

@Override
@MongoSwitch("common")
public void deleteById(String id) {
super.deleteById(id);
}


+ 1
- 1
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java 查看文件

@@ -24,7 +24,7 @@ import java.net.InetSocketAddress;
@Slf4j
public class DipperPositionServer {

@Value(value = "${position.serverAddr}")
@Value(value = "${position.server.serverAddr}")
private String serverAddr;

@Value(value = "${position.server.timeAsycPort}")


+ 4
- 3
src/main/resources/bootstrap.yaml 查看文件

@@ -29,6 +29,7 @@ pos:

position:
server:
timeAsycPort:
posAsycPort:
starsAsycPort:
serverAddr: 172.16.192.26
timeAsycPort: 9011
posAsycPort: 9013
starsAsycPort: 9012

正在加载...
取消
保存