FrontServiceApplicationStart.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.java110.front;
  2. import com.java110.service.init.ServiceStartInit;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.boot.SpringApplication;
  6. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  9. import org.springframework.boot.web.client.RestTemplateBuilder;
  10. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  11. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  12. import org.springframework.context.ApplicationContext;
  13. import org.springframework.context.annotation.Bean;
  14. import org.springframework.http.converter.StringHttpMessageConverter;
  15. import org.springframework.web.client.RestTemplate;
  16. import java.nio.charset.Charset;
  17. /**
  18. * spring boot 初始化启动类
  19. *
  20. * @version v0.1
  21. * @auther com.java110.wuxw
  22. * @mail 928255095@qq.com
  23. * @date 2016年8月6日
  24. * @tag
  25. */
  26. @SpringBootApplication(scanBasePackages = {
  27. "com.java110.service.configuration",
  28. "com.java110.service.init",
  29. "com.java110.front",
  30. "com.java110.core",
  31. "com.java110.config.properties.code",
  32. "com.java110.report"
  33. })
  34. @EnableDiscoveryClient
  35. //@EnableConfigurationProperties(EventProperties.class)
  36. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
  37. public class FrontServiceApplicationStart {
  38. private static Logger logger = LoggerFactory.getLogger(FrontServiceApplicationStart.class);
  39. /**
  40. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  41. *
  42. * @return restTemplate
  43. */
  44. @Bean
  45. public RestTemplate outRestTemplate() {
  46. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  47. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
  48. return restTemplate;
  49. }
  50. /**
  51. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  52. *
  53. * @return restTemplate
  54. */
  55. @Bean
  56. @LoadBalanced
  57. public RestTemplate restTemplate() {
  58. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  59. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
  60. return restTemplate;
  61. }
  62. public static void main(String[] args) throws Exception {
  63. try {
  64. ApplicationContext context = SpringApplication.run(FrontServiceApplicationStart.class, args);
  65. ServiceStartInit.initSystemConfig(context);
  66. //VueComponentTemplate.initComponent(VueComponentTemplate.DEFAULT_COMPONENT_PACKAGE_PATH);
  67. } catch (Throwable e) {
  68. logger.error("系统启动失败", e);
  69. }
  70. }
  71. }