FrontServiceApplicationStart.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.front;
  17. import com.java110.core.smo.impl.ComputeFeeSMOImpl;
  18. import com.java110.service.init.ServiceStartInit;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.boot.SpringApplication;
  22. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  23. import org.springframework.boot.autoconfigure.SpringBootApplication;
  24. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  25. import org.springframework.boot.web.client.RestTemplateBuilder;
  26. import org.springframework.cache.annotation.EnableCaching;
  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.context.annotation.ComponentScan;
  33. import org.springframework.context.annotation.FilterType;
  34. import org.springframework.http.converter.StringHttpMessageConverter;
  35. import org.springframework.web.client.RestTemplate;
  36. import java.nio.charset.Charset;
  37. /**
  38. * spring boot 初始化启动类
  39. *
  40. * @version v0.1
  41. * @auther com.java110.wuxw
  42. * @mail 928255095@qq.com
  43. * @date 2016年8月6日
  44. * @tag
  45. *
  46. * , excludeFilters =
  47. * {
  48. * @ComponentScan.Filter(type = FilterType.REGEX,pattern = "com.java110.core.smo.*")
  49. * }
  50. */
  51. @SpringBootApplication
  52. @ComponentScan(basePackages = { "com.java110.service.configuration",
  53. "com.java110.service.init",
  54. "com.java110.front",
  55. "com.java110.core",
  56. "com.java110.config.properties.code",
  57. "com.java110.report"})
  58. @EnableDiscoveryClient
  59. //@EnableConfigurationProperties(EventProperties.class)
  60. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
  61. @EnableCaching
  62. @EnableFeignClients(basePackages = {"com.java110.intf.order"})
  63. public class FrontServiceApplicationStart {
  64. private static Logger logger = LoggerFactory.getLogger(FrontServiceApplicationStart.class);
  65. /**
  66. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  67. *
  68. * @return restTemplate
  69. */
  70. @Bean
  71. public RestTemplate outRestTemplate() {
  72. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  73. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
  74. return restTemplate;
  75. }
  76. /**
  77. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  78. *
  79. * @return restTemplate
  80. */
  81. @Bean
  82. @LoadBalanced
  83. public RestTemplate restTemplate() {
  84. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  85. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
  86. return restTemplate;
  87. }
  88. public static void main(String[] args) throws Exception {
  89. try {
  90. ApplicationContext context = SpringApplication.run(FrontServiceApplicationStart.class, args);
  91. ServiceStartInit.initSystemConfig(context);
  92. //VueComponentTemplate.initComponent(VueComponentTemplate.DEFAULT_COMPONENT_PACKAGE_PATH);
  93. } catch (Throwable e) {
  94. logger.error("系统启动失败", e);
  95. }
  96. }
  97. }