123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package com.yihu;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.web.servlet.MultipartConfigFactory;
- import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
- import org.springframework.cloud.client.loadbalancer.LoadBalanced;
- import org.springframework.context.annotation.Bean;
- import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
- import org.springframework.scheduling.annotation.EnableAsync;
- import org.springframework.web.client.RestTemplate;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
- import javax.servlet.MultipartConfigElement;
- /**
- * Created by chenweida on 2017/5/10.
- * localhost:10020/refresh 刷新当个微服务的配置 可以在需要刷新的bean上面@RefreshScope
- */
- @SpringBootApplication
- @EnableJpaAuditing
- @EnableAsync
- public class SvrBaseApplication extends SpringBootServletInitializer {
- public static void main(String[] args) {
- SpringApplication.run(SvrBaseApplication.class, args);
- }
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
- return builder.sources(SvrBaseApplication.class);
- }
- @Bean
- MultipartConfigElement multipartConfigElement() {
- MultipartConfigFactory factory = new MultipartConfigFactory();
- factory.setLocation("/home/temp");
- return factory.createMultipartConfig();
- }
- @LoadBalanced//为RestTemplate Bean添加了一个LoadBalancerInterceptor拦截器。可以将请求的地址中的服务逻辑名转为具体的服务地址
- @Bean//将RestTemplate注册到容器
- public RestTemplate RestTemplate(){
- return new RestTemplate();
- }
- }
|