美文网首页
spring cloud--概念特点

spring cloud--概念特点

作者: 李霖神谷 | 来源:发表于2020-05-18 11:21 被阅读0次

    为什么要使用微服务;
    他的风格是将一个单一应用程序开发成一组小型服务的,每一个服务运行在自己的进程中,采取的是独立部署的方式,服务可以用不同的语言开发,使用不同的存储技术。
    多服务的一个简单的例子:订单服务能够根据订单号获取订单信息,订单信息里面包括商品信息,获取商品信息是在另外一个服上。
    启动类

    @SpringBootApplication
    @ComponentScan(basePackages = {"com.shuai"})
    public class OrderApp {
        public static void main(String[] args) {
            SpringApplication.run(OrderApp.class,args);
            System.out.println("kkkkkkkkkkkkkkkkkkkkkkkkk");
        }
    //    向工厂添加类
        @Bean
        public RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }
    

    访问商品服务的service层

    
    @Service
    public class IteamService {
        @Autowired
        RestTemplate restTemplate;
    
        @Value("${myspcloud.iteam.url}")
         String iteamUrl;
        public Iteam getIteam(String id) {
            return restTemplate.getForObject(iteamUrl + id, Iteam.class);
        }
    
    }
    配置文件:
    server:
      port: 8082
    
    myspcloud:
      iteam:
        url: http://localhost:8081/iteam/
    
    

    相关文章

      网友评论

          本文标题:spring cloud--概念特点

          本文链接:https://www.haomeiwen.com/subject/jgquohtx.html