OaServiceApplicationStart.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.oa;
  17. import com.java110.core.annotation.Java110ListenerDiscovery;
  18. import com.java110.core.client.RestTemplate;
  19. import com.java110.core.event.service.BusinessServiceDataFlowEventPublishing;
  20. import com.java110.service.init.ServiceStartInit;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.boot.SpringApplication;
  24. import org.springframework.boot.autoconfigure.SpringBootApplication;
  25. import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
  26. import org.springframework.boot.web.client.RestTemplateBuilder;
  27. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  28. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  29. import org.springframework.cloud.openfeign.EnableFeignClients;
  30. import org.springframework.context.ApplicationContext;
  31. import org.springframework.context.annotation.Bean;
  32. import org.springframework.http.converter.StringHttpMessageConverter;
  33. import java.nio.charset.Charset;
  34. /**
  35. * spring boot 初始化启动类
  36. *
  37. * @version v0.1
  38. * @auther com.java110.wuxw
  39. * @mail 928255095@qq.com
  40. * @date 2016年8月6日
  41. * @tag
  42. */
  43. @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.oa",
  44. "com.java110.core", "com.java110.config.properties.code", "com.java110.db"})
  45. @EnableDiscoveryClient
  46. @Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class,
  47. basePackages = {"com.java110.oa.listener"})
  48. @EnableFeignClients(basePackages = {"com.java110.intf.user",
  49. "com.java110.intf.order",
  50. "com.java110.intf.community",
  51. "com.java110.intf.common",
  52. "com.java110.intf.store"})
  53. public class OaServiceApplicationStart {
  54. private static Logger logger = LoggerFactory.getLogger(OaServiceApplicationStart.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 RestTemplate outRestTemplate() {
  74. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  75. com.java110.core.client.RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class);
  76. return restTemplate;
  77. }
  78. public static void main(String[] args) throws Exception {
  79. ApplicationContext context = SpringApplication.run(OaServiceApplicationStart.class, args);
  80. ServiceStartInit.initSystemConfig(context);
  81. }
  82. }