SvrBaseApplication.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.yihu;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.boot.builder.SpringApplicationBuilder;
  5. import org.springframework.boot.web.servlet.MultipartConfigFactory;
  6. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  7. import org.springframework.cloud.client.loadbalancer.LoadBalanced;
  8. import org.springframework.context.annotation.Bean;
  9. import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
  10. import org.springframework.scheduling.annotation.EnableAsync;
  11. import org.springframework.web.client.RestTemplate;
  12. import springfox.documentation.swagger2.annotations.EnableSwagger2;
  13. import javax.servlet.MultipartConfigElement;
  14. /**
  15. * Created by chenweida on 2017/5/10.
  16. * localhost:10020/refresh 刷新当个微服务的配置 可以在需要刷新的bean上面@RefreshScope
  17. */
  18. @SpringBootApplication
  19. @EnableJpaAuditing
  20. @EnableAsync
  21. public class SvrBaseApplication extends SpringBootServletInitializer {
  22. public static void main(String[] args) {
  23. SpringApplication.run(SvrBaseApplication.class, args);
  24. }
  25. @Override
  26. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  27. return builder.sources(SvrBaseApplication.class);
  28. }
  29. @Bean
  30. MultipartConfigElement multipartConfigElement() {
  31. MultipartConfigFactory factory = new MultipartConfigFactory();
  32. factory.setLocation("/home/temp");
  33. return factory.createMultipartConfig();
  34. }
  35. @LoadBalanced//为RestTemplate Bean添加了一个LoadBalancerInterceptor拦截器。可以将请求的地址中的服务逻辑名转为具体的服务地址
  36. @Bean//将RestTemplate注册到容器
  37. public RestTemplate RestTemplate(){
  38. return new RestTemplate();
  39. }
  40. }