WebServiceApplicationStart.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.java110.web;
  2. import com.java110.service.init.ServiceStartInit;
  3. import com.java110.web.core.VueComponentTemplate;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.boot.SpringApplication;
  7. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  8. import org.springframework.boot.autoconfigure.SpringBootApplication;
  9. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  10. import org.springframework.boot.web.client.RestTemplateBuilder;
  11. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  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 = {"com.java110.service.aop",
  27. "com.java110.service.configuration",
  28. "com.java110.service.controller",
  29. "com.java110.service.filter",
  30. "com.java110.service.init",
  31. "com.java110.web",
  32. "com.java110.core",
  33. "com.java110.config.properties.code",
  34. "com.java110.cache",
  35. "com.java110.report"
  36. })
  37. @EnableDiscoveryClient
  38. //@EnableConfigurationProperties(EventProperties.class)
  39. @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
  40. public class WebServiceApplicationStart {
  41. private static Logger logger = LoggerFactory.getLogger(WebServiceApplicationStart.class);
  42. /**
  43. * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力.
  44. *
  45. * @return restTemplate
  46. */
  47. @Bean
  48. //@LoadBalanced
  49. public RestTemplate restTemplate() {
  50. StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
  51. RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build();
  52. return restTemplate;
  53. }
  54. public static void main(String[] args) throws Exception {
  55. try {
  56. ApplicationContext context = SpringApplication.run(WebServiceApplicationStart.class, args);
  57. ServiceStartInit.initSystemConfig(context);
  58. VueComponentTemplate.initComponent(VueComponentTemplate.DEFAULT_COMPONENT_PACKAGE_PATH);
  59. }catch (Throwable e){
  60. logger.error("系统启动失败",e);
  61. }
  62. }
  63. }