AcctServiceApplicationStart.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.java110.acct;
  2. import com.java110.core.annotation.Java110ListenerDiscovery;
  3. import com.java110.core.client.RestTemplate;
  4. import com.java110.core.event.service.BusinessServiceDataFlowEventPublishing;
  5. import com.java110.service.init.ServiceStartInit;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.boot.SpringApplication;
  9. import org.springframework.boot.autoconfigure.SpringBootApplication;
  10. import org.springframework.boot.web.client.RestTemplateBuilder;
  11. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  12. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  13. import org.springframework.cloud.openfeign.EnableFeignClients;
  14. import org.springframework.context.ApplicationContext;
  15. import org.springframework.context.annotation.Bean;
  16. import org.springframework.http.converter.StringHttpMessageConverter;
  17. import java.nio.charset.Charset;
  18. /**
  19. * spring boot 初始化启动类
  20. *
  21. * @version v0.1
  22. * @auther com.java110.wuxw
  23. * @mail 928255095@qq.com
  24. * @date 2016年8月6日
  25. * @tag
  26. */
  27. @SpringBootApplication(
  28. scanBasePackages = {"com.java110.service","com.java110.core", "com.java110.acct", "com.java110.config.properties.code", "com.java110.db"},
  29. excludeName = {"com.java110.intf.acct"}
  30. )
  31. @EnableDiscoveryClient
  32. @Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class,
  33. basePackages = {"com.java110.acct.listener"})
  34. @EnableFeignClients(basePackages = {"com.java110.intf.community","com.java110.intf.common","com.java110.intf.store",
  35. "com.java110.intf.fee","com.java110.intf.order","com.java110.intf.user"})
  36. public class AcctServiceApplicationStart {
  37. private static Logger logger = LoggerFactory.getLogger(AcctServiceApplicationStart.class);
  38. private static final String LISTENER_PATH = "java110.UserService.listeners";
  39. public static void main(String[] args) throws Exception {
  40. try {
  41. ApplicationContext context = SpringApplication.run(AcctServiceApplicationStart.class, args);
  42. ServiceStartInit.initSystemConfig(context);
  43. //加载业务侦听
  44. // SystemStartLoadBusinessConfigure.initSystemConfig(LISTENER_PATH);
  45. } catch (Throwable e) {
  46. logger.error("系统启动失败", e);
  47. }
  48. }
  49. /**
  50. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  51. *
  52. * @return restTemplate
  53. */
  54. @Bean
  55. @LoadBalanced
  56. public RestTemplate restTemplate() {
  57. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  58. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
  59. return restTemplate;
  60. }
  61. }