CommunityServiceApplicationStart.java 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.community;
  17. import com.java110.core.annotation.Java110CmdDiscovery;
  18. import com.java110.core.annotation.Java110ListenerDiscovery;
  19. import com.java110.core.client.RestTemplate;
  20. import com.java110.core.event.cmd.ServiceCmdEventPublishing;
  21. import com.java110.core.event.service.BusinessServiceDataFlowEventPublishing;
  22. import com.java110.service.init.ServiceStartInit;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.boot.SpringApplication;
  26. import org.springframework.boot.autoconfigure.SpringBootApplication;
  27. import org.springframework.boot.web.client.RestTemplateBuilder;
  28. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  29. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  30. import org.springframework.cloud.openfeign.EnableFeignClients;
  31. import org.springframework.context.ApplicationContext;
  32. import org.springframework.context.annotation.Bean;
  33. import org.springframework.http.converter.StringHttpMessageConverter;
  34. import java.nio.charset.Charset;
  35. /**
  36. * spring boot 初始化启动类
  37. *
  38. * @version v0.1
  39. * @auther com.java110.wuxw
  40. * @mail 928255095@qq.com
  41. * @date 2016年8月6日
  42. * @tag
  43. */
  44. @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.community",
  45. "com.java110.core", "com.java110.config.properties.code", "com.java110.db"})
  46. @EnableDiscoveryClient
  47. @Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class,
  48. basePackages = {"com.java110.community.listener"})
  49. @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class,
  50. basePackages = {"com.java110.community.cmd"})
  51. @EnableFeignClients(basePackages = {"com.java110.intf.user", "com.java110.intf.common", "com.java110.intf.fee",
  52. "com.java110.intf.order"})
  53. public class CommunityServiceApplicationStart {
  54. private static Logger logger = LoggerFactory.getLogger(CommunityServiceApplicationStart.class);
  55. /**
  56. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  57. *
  58. * @return restTemplate
  59. */
  60. @Bean
  61. @LoadBalanced
  62. public RestTemplate restTemplate() {
  63. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  64. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
  65. return restTemplate;
  66. }
  67. /**
  68. * 实例化RestTemplate
  69. *
  70. * @return restTemplate
  71. */
  72. @Bean
  73. public com.java110.core.client.RestTemplate outRestTemplate() {
  74. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  75. com.java110.core.client.RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(com.java110.core.client.RestTemplate.class);
  76. return restTemplate;
  77. }
  78. public static void main(String[] args) throws Exception {
  79. try {
  80. ApplicationContext context = SpringApplication.run(CommunityServiceApplicationStart.class, args);
  81. ServiceStartInit.initSystemConfig(context);
  82. } catch (Throwable e) {
  83. logger.error("系统启动失败", e);
  84. }
  85. }
  86. }