Pārlūkot izejas kodu

增加配置文件读取

tags/v1.0.0^2
林万龙 pirms 3 gadiem
vecāks
revīzija
777127d168
5 mainītis faili ar 34 papildinājumiem un 6 dzēšanām
  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 Parādīt failu

@@ -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 Parādīt failu

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


private static final Map<String, MongoDbFactory> MONGO_CLIENT_DB_FACTORY_MAP = new HashMap<>(); 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 @Autowired
MongoListProperties mongoListProperties; MongoListProperties mongoListProperties;




+ 6
- 0
src/main/java/com/telpo/dipperposition/mapper/IPProvinceMapper.java Parādīt failu

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


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


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


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


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


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


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


+ 1
- 1
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java Parādīt failu

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


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


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


+ 4
- 3
src/main/resources/bootstrap.yaml Parādīt failu

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


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

Notiek ielāde…
Atcelt
Saglabāt