Commit 8b86bea52aa3560a119f94e6ddd961c207cf029e
1 parent
69222f2e
1、添加dubboAutoConfig功能,包括pom修改,相关配置文件,具体参看common-config工程中dubbo包下readme.txt文件
2、修改相关control_facade,配合dubboAutoConfig,主要是@Reference标注的用法 3、添加actuator功能,具体参看1的readme.txt文件
Showing
11 changed files
with
87 additions
and
33 deletions
pom.xml
| ... | ... | @@ -15,6 +15,11 @@ |
| 15 | 15 | </parent> |
| 16 | 16 | |
| 17 | 17 | <dependencies> |
| 18 | + <dependency> | |
| 19 | + <groupId>org.springframework.boot</groupId> | |
| 20 | + <artifactId>spring-boot-starter-actuator</artifactId> | |
| 21 | + </dependency> | |
| 22 | + | |
| 18 | 23 | <dependency> |
| 19 | 24 | <groupId>org.springframework.boot</groupId> |
| 20 | 25 | <artifactId>spring-boot-starter-web</artifactId> |
| ... | ... | @@ -308,6 +313,10 @@ |
| 308 | 313 | <groupId>org.springframework</groupId> |
| 309 | 314 | <artifactId>spring</artifactId> |
| 310 | 315 | </exclusion> |
| 316 | + <exclusion> | |
| 317 | + <groupId>log4j</groupId> | |
| 318 | + <artifactId>log4j</artifactId> | |
| 319 | + </exclusion> | |
| 311 | 320 | </exclusions> |
| 312 | 321 | </dependency> |
| 313 | 322 | |
| ... | ... | @@ -344,12 +353,35 @@ |
| 344 | 353 | <!--</dependency>--> |
| 345 | 354 | <!-- dubbo 需要的jar end --> |
| 346 | 355 | |
| 347 | - <!-- common工程依赖 --> | |
| 356 | + <!-- plan common工程依赖 --> | |
| 348 | 357 | <dependency> |
| 349 | 358 | <groupId>com.bsth.control_v2</groupId> |
| 350 | 359 | <artifactId>plan_module-common</artifactId> |
| 351 | 360 | <version>1.0-SNAPSHOT</version> |
| 352 | 361 | </dependency> |
| 362 | + <!-- plan common config 工程依赖 --> | |
| 363 | + <dependency> | |
| 364 | + <groupId>com.bsth.control_v2</groupId> | |
| 365 | + <artifactId>plan_module-common-config</artifactId> | |
| 366 | + <version>1.0-SNAPSHOT</version> | |
| 367 | + </dependency> | |
| 368 | + | |
| 369 | + <dependency> | |
| 370 | + <groupId>org.slf4j</groupId> | |
| 371 | + <artifactId>slf4j-api</artifactId> | |
| 372 | + <version>1.7.7</version> | |
| 373 | + </dependency> | |
| 374 | + <dependency> | |
| 375 | + <groupId>ch.qos.logback</groupId> | |
| 376 | + <artifactId>logback-classic</artifactId> | |
| 377 | + <version>1.1.3</version> | |
| 378 | + </dependency> | |
| 379 | + <dependency> | |
| 380 | + <groupId>org.slf4j</groupId> | |
| 381 | + <artifactId>log4j-over-slf4j</artifactId> | |
| 382 | + <version>1.7.7</version> | |
| 383 | + </dependency> | |
| 384 | + | |
| 353 | 385 | </dependencies> |
| 354 | 386 | |
| 355 | 387 | <dependencyManagement> | ... | ... |
src/main/java/com/bsth/common/Constants.java
| ... | ... | @@ -21,6 +21,9 @@ public class Constants { |
| 21 | 21 | public static final String LOGIN_FAILURE = "/user/loginFailure"; |
| 22 | 22 | public static final String CAPTCHA = "/captcha.jpg"; |
| 23 | 23 | |
| 24 | + // springboot manage health的检测url | |
| 25 | + public static final String ACTUATOR_MANAGEMENT_HEALTH = "/manage/health"; | |
| 26 | + | |
| 24 | 27 | //对外的营运数据接口 |
| 25 | 28 | public static final String SERVICE_INTERFACE = "/companyService/**"; |
| 26 | 29 | ... | ... |
src/main/java/com/bsth/controller/schedule/BController_facade.java
| ... | ... | @@ -17,9 +17,8 @@ import java.util.HashMap; |
| 17 | 17 | import java.util.List; |
| 18 | 18 | import java.util.Map; |
| 19 | 19 | |
| 20 | -public class BController_facade<Id extends Serializable, DTO> { | |
| 21 | - @Autowired | |
| 22 | - private BServiceFacade<Id, DTO> bServiceFacade; | |
| 20 | +public abstract class BController_facade<Id extends Serializable, DTO> { | |
| 21 | + protected abstract BServiceFacade<Id, DTO> getBServiceFacade(); | |
| 23 | 22 | |
| 24 | 23 | @Autowired |
| 25 | 24 | private SysUserService sysUserService; |
| ... | ... | @@ -43,7 +42,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 43 | 42 | |
| 44 | 43 | Map<String, Object> rtn = new HashMap<>(); |
| 45 | 44 | try { |
| 46 | - DTO dto_saved = bServiceFacade.save(dto); | |
| 45 | + DTO dto_saved = getBServiceFacade().save(dto); | |
| 47 | 46 | rtn.put("status", ResponseCode.SUCCESS); |
| 48 | 47 | rtn.put("data", dto_saved); |
| 49 | 48 | } catch (Exception exp) { |
| ... | ... | @@ -63,7 +62,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 63 | 62 | |
| 64 | 63 | Map<String, Object> rtn = new HashMap<>(); |
| 65 | 64 | try { |
| 66 | - DTO dto_updated = bServiceFacade.save(dto); | |
| 65 | + DTO dto_updated = getBServiceFacade().save(dto); | |
| 67 | 66 | rtn.put("status", ResponseCode.SUCCESS); |
| 68 | 67 | rtn.put("data", dto_updated); |
| 69 | 68 | } catch (Exception exp) { |
| ... | ... | @@ -79,7 +78,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 79 | 78 | public Map<String, Object> findById(@PathVariable("id") Id id) { |
| 80 | 79 | Map<String, Object> rtn = new HashMap<>(); |
| 81 | 80 | try { |
| 82 | - DTO dto = bServiceFacade.findById(id); | |
| 81 | + DTO dto = getBServiceFacade().findById(id); | |
| 83 | 82 | rtn.put("status", ResponseCode.SUCCESS); |
| 84 | 83 | rtn.put("data", dto); |
| 85 | 84 | } catch (Exception exp) { |
| ... | ... | @@ -95,7 +94,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 95 | 94 | public Map<String, Object> list(@RequestParam Map<String, Object> param) { |
| 96 | 95 | Map<String, Object> rtn = new HashMap<>(); |
| 97 | 96 | try { |
| 98 | - List<DTO> tList = bServiceFacade.list(param); | |
| 97 | + List<DTO> tList = getBServiceFacade().list(param); | |
| 99 | 98 | rtn.put("status", ResponseCode.SUCCESS); |
| 100 | 99 | rtn.put("data", tList); |
| 101 | 100 | } catch (Exception exp) { |
| ... | ... | @@ -121,7 +120,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 121 | 120 | .build(); |
| 122 | 121 | Map<String, Object> rtn = new HashMap<>(); |
| 123 | 122 | try { |
| 124 | - rtn.put("data", bServiceFacade.list(map, pageRequestDto)); | |
| 123 | + rtn.put("data", getBServiceFacade().list(map, pageRequestDto)); | |
| 125 | 124 | rtn.put("status", ResponseCode.SUCCESS); |
| 126 | 125 | } catch (Exception exp) { |
| 127 | 126 | rtn.put("status", ResponseCode.ERROR); |
| ... | ... | @@ -136,7 +135,7 @@ public class BController_facade<Id extends Serializable, DTO> { |
| 136 | 135 | Map<String, Object> rtn = new HashMap<>(); |
| 137 | 136 | try { |
| 138 | 137 | // 由于种种原因,这里不保存用户和操作时间了 |
| 139 | - bServiceFacade.delete(id); | |
| 138 | + getBServiceFacade().delete(id); | |
| 140 | 139 | rtn.put("status", ResponseCode.SUCCESS); |
| 141 | 140 | } catch (Exception exp) { |
| 142 | 141 | rtn.put("status", ResponseCode.ERROR); | ... | ... |
src/main/java/com/bsth/controller/schedule/core/SchedulePlanController_dubbo.java
| 1 | 1 | package com.bsth.controller.schedule.core; |
| 2 | 2 | |
| 3 | +import com.alibaba.dubbo.config.annotation.Reference; | |
| 3 | 4 | import com.bsth.common.ResponseCode; |
| 4 | 5 | import com.bsth.control_v2.plan_module.common.dto.schedule.PlanDto; |
| 6 | +import com.bsth.control_v2.plan_module.common.service.BServiceFacade; | |
| 7 | +import com.bsth.control_v2.plan_module.common.service.schedule.PlanServiceFacade; | |
| 5 | 8 | import com.bsth.control_v2.plan_module.common.service.schedule.validate.PlanPreValidateFacade; |
| 6 | 9 | import com.bsth.controller.schedule.BController_facade; |
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | 10 | import org.springframework.web.bind.annotation.PathVariable; |
| 9 | 11 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | 12 | import org.springframework.web.bind.annotation.RequestMethod; |
| ... | ... | @@ -17,8 +19,15 @@ import java.util.Map; |
| 17 | 19 | @RestController |
| 18 | 20 | @RequestMapping("spc") |
| 19 | 21 | public class SchedulePlanController_dubbo extends BController_facade<Long, PlanDto> { |
| 20 | - @Autowired | |
| 22 | +// @Reference | |
| 21 | 23 | private PlanPreValidateFacade planPreValidateFacade; |
| 24 | + @Reference | |
| 25 | + private PlanServiceFacade planInfoServiceFacade; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + protected BServiceFacade<Long, PlanDto> getBServiceFacade() { | |
| 29 | + return planInfoServiceFacade; | |
| 30 | + } | |
| 22 | 31 | |
| 23 | 32 | // TODO:save方法独立出来 |
| 24 | 33 | ... | ... |
src/main/java/com/bsth/controller/schedule/core/SchedulePlanInfoController_dubbo.java
| 1 | 1 | package com.bsth.controller.schedule.core; |
| 2 | 2 | |
| 3 | +import com.alibaba.dubbo.config.annotation.Reference; | |
| 3 | 4 | import com.bsth.common.ResponseCode; |
| 4 | 5 | import com.bsth.control_v2.plan_module.common.dto.schedule.PlanInfoDto; |
| 5 | 6 | import com.bsth.control_v2.plan_module.common.dto.sys.UserDto; |
| 6 | 7 | import com.bsth.control_v2.plan_module.common.service.BServiceFacade; |
| 7 | 8 | import com.bsth.control_v2.plan_module.common.service.schedule.PlanInfoServiceFacade; |
| 8 | -import com.bsth.control_v2.plan_module.common.service.schedule.PlanServiceFacade; | |
| 9 | 9 | import com.bsth.controller.schedule.BController_facade; |
| 10 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | 10 | import org.springframework.web.bind.annotation.PathVariable; |
| 12 | 11 | import org.springframework.web.bind.annotation.RequestMapping; |
| 13 | 12 | import org.springframework.web.bind.annotation.RequestMethod; |
| ... | ... | @@ -20,10 +19,15 @@ import java.util.Map; |
| 20 | 19 | @RestController |
| 21 | 20 | @RequestMapping("spic") |
| 22 | 21 | public class SchedulePlanInfoController_dubbo extends BController_facade<Long, PlanInfoDto> { |
| 23 | - @Autowired | |
| 22 | + @Reference | |
| 24 | 23 | private PlanInfoServiceFacade planInfoServiceFacade; |
| 25 | 24 | |
| 26 | 25 | @Override |
| 26 | + protected BServiceFacade<Long, PlanInfoDto> getBServiceFacade() { | |
| 27 | + return planInfoServiceFacade; | |
| 28 | + } | |
| 29 | + | |
| 30 | + @Override | |
| 27 | 31 | public void setCreateUserInfo(PlanInfoDto planInfoDto, Integer userId, Date createDate) { |
| 28 | 32 | UserDto userDto = UserDto.getBuilder() |
| 29 | 33 | .setId(userId) | ... | ... |
src/main/java/com/bsth/filter/BaseFilter.java
| ... | ... | @@ -16,8 +16,12 @@ public abstract class BaseFilter implements Filter { |
| 16 | 16 | /** |
| 17 | 17 | * 白名单 |
| 18 | 18 | */ |
| 19 | - private String[] whiteListURLs = { Constants.LOGIN_PAGE,Constants.CAPTCHA, Constants.SERVICE_INTERFACE, | |
| 20 | - Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL, Constants.XD_CHILD_PAGES, Constants.XD_REAL_GPS, Constants.UP_RFID_URL, Constants.STATION_AND_SECTION_COUNT }; | |
| 19 | + private String[] whiteListURLs = { | |
| 20 | + Constants.LOGIN_PAGE,Constants.CAPTCHA, Constants.SERVICE_INTERFACE, | |
| 21 | + Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, | |
| 22 | + Constants.LOGIN, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL, | |
| 23 | + Constants.XD_CHILD_PAGES, Constants.XD_REAL_GPS, Constants.UP_RFID_URL, | |
| 24 | + Constants.STATION_AND_SECTION_COUNT, Constants.ACTUATOR_MANAGEMENT_HEALTH }; | |
| 21 | 25 | |
| 22 | 26 | @Override |
| 23 | 27 | public void destroy() { | ... | ... |
src/main/java/com/bsth/service/schedule/dubbo/DubboConfig.java deleted
100644 → 0
| 1 | -package com.bsth.service.schedule.dubbo; | |
| 2 | - | |
| 3 | -import org.springframework.context.annotation.Configuration; | |
| 4 | -import org.springframework.context.annotation.ImportResource; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * Dubbo消费者配置。 | |
| 8 | - */ | |
| 9 | -@Configuration | |
| 10 | -@ImportResource({"classpath:dubbo/applicationContext_dubbo_consumer.xml"}) | |
| 11 | -public class DubboConfig { | |
| 12 | - | |
| 13 | -} |
src/main/resources/application-dev.properties
| 1 | 1 | server.port=9088 |
| 2 | -management.port= 9001 | |
| 3 | -management.address= 127.0.0.1 | |
| 2 | +#management.port= 9001 | |
| 3 | +#management.address= 127.0.0.1 | |
| 4 | +management.security.enabled=false | |
| 5 | +management.context-path=/manage | |
| 6 | +dubbo.use=false | |
| 4 | 7 | |
| 5 | 8 | spring.jpa.hibernate.ddl-auto= none |
| 6 | 9 | spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy | ... | ... |
src/main/resources/dubbo/applicationContext_dubbo_consumer.xml
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | <!-- 使用zookeeper注册中心暴露服务地址 --> |
| 12 | 12 | <!-- 注册中心地址 --> |
| 13 | - <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" /> | |
| 13 | + <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" check="false" /> | |
| 14 | 14 | |
| 15 | 15 | <!-- 计划排班服务接口 --> |
| 16 | 16 | <dubbo:reference interface="com.bsth.control_v2.plan_module.common.service.schedule.PlanServiceFacade" id="planServiceFacadeImpl" check="false" /> | ... | ... |
src/main/resources/dubbo/config-dev.properties
0 → 100644
| 1 | +# application名字 | |
| 2 | +spring.dubbo.application.name=bsth_control_v2 | |
| 3 | +# zookeeper注册中心地址 | |
| 4 | +spring.dubbo.registry=zookeeper://127.0.0.1:2181 | |
| 5 | + | |
| 6 | +#----------- dubbo:consumer 性能调优选项 -------------# | |
| 7 | +# 远程服务调用超时时间,单位毫秒,这里设置30分钟 | |
| 8 | +spring.dubbo.consumer.timeout=1800000 | |
| 9 | +# 远程服务调用重试次数,0表示不需要重试 | |
| 10 | +spring.dubbo.consumer.retries=0 | |
| 11 | +#----------- dubbo:consumer 服务治理选项 -------------# | |
| 12 | +# 启动不检查提供者是否存在 | |
| 13 | +spring.dubbo.consumer.check=false | |
| 0 | 14 | \ No newline at end of file | ... | ... |
src/main/resources/dubbo/config-prod.properties
0 → 100644