CommonServiceApplicationStart.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.common;
  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.autoconfigure.liquibase.LiquibaseAutoConfiguration;
  28. import org.springframework.boot.web.client.RestTemplateBuilder;
  29. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  30. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  31. import org.springframework.cloud.openfeign.EnableFeignClients;
  32. import org.springframework.context.ApplicationContext;
  33. import org.springframework.context.annotation.Bean;
  34. import org.springframework.http.converter.StringHttpMessageConverter;
  35. import java.nio.charset.Charset;
  36. /**
  37. * spring boot 初始化启动类
  38. *
  39. * @version v0.1
  40. * @auther com.java110.wuxw
  41. * @mail 928255095@qq.com
  42. * @date 2016年8月6日
  43. * @tag
  44. */
  45. @SpringBootApplication(scanBasePackages = {
  46. "com.java110.service",
  47. "com.java110.common",
  48. "com.java110.core",
  49. "com.java110.config.properties.code",
  50. "com.java110.db"},
  51. exclude = {LiquibaseAutoConfiguration.class,
  52. org.activiti.spring.boot.SecurityAutoConfiguration.class,
  53. org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class}
  54. )
  55. @EnableDiscoveryClient
  56. @Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class,
  57. basePackages = {"com.java110.common.listener"})
  58. @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class,
  59. basePackages = {"com.java110.common.cmd"})
  60. @EnableFeignClients(basePackages = {
  61. "com.java110.intf.user",
  62. "com.java110.intf.store",
  63. "com.java110.intf.fee",
  64. "com.java110.intf.community",
  65. "com.java110.intf.job",
  66. "com.java110.intf.order",
  67. "com.java110.intf.oa",
  68. "com.java110.intf.report"
  69. })
  70. public class CommonServiceApplicationStart {
  71. private static Logger logger = LoggerFactory.getLogger(CommonServiceApplicationStart.class);
  72. /**
  73. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  74. *
  75. * @return restTemplate
  76. */
  77. @Bean
  78. @LoadBalanced
  79. public RestTemplate restTemplate() {
  80. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  81. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
  82. return restTemplate;
  83. }
  84. /**
  85. * 实例化RestTemplate
  86. *
  87. * @return restTemplate
  88. */
  89. @Bean
  90. public RestTemplate outRestTemplate() {
  91. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  92. com.java110.core.client.RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
  93. return restTemplate;
  94. }
  95. public static void main(String[] args) throws Exception {
  96. ServiceStartInit.preInitSystemConfig();
  97. ApplicationContext context = SpringApplication.run(CommonServiceApplicationStart.class, args);
  98. ServiceStartInit.initSystemConfig(context);
  99. //初始化 activity 流程
  100. //DeploymentActivity.deploymentProcess();
  101. }
  102. }