Using Resttemplate in Springboot.

Source: Internet
Author: User

I. Preface

Instructions for use of official website

Get Eureka Instance

Public String serviceurl () {Instanceinfo instance = Discoveryclient.getnextserverfromeureka ("STORES", false); return Instance.gethomepageurl ();}


Steps:


Two. Importing packages

Pom.xml

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId> Spring-cloud-starter-eureka</artifactid></dependency><dependency> <groupId> Org.springframework.cloud</groupid> <artifactId>spring-cloud-starter-hystrix</artifactId>< /dependency>


Three. Modify the startup application

@EnableCircuitBreaker @enablediscoveryclientpublic class Helllomain {@Bean @loadbalancedresttemplate resttemplate () { return new Resttemplate ();} public static void Main (string[] args) {Springapplication.run (hellomain.class, args);}}


Four. Business use

private int xxxx (String body) {resttemplate resttemplate = new Resttemplate (); Httpheaders headers = new Httpheaders (); MediaType type = Mediatype.parsemediatype ("Application/json"); Headers.setcontenttype (type); httpentity<string> formentity = new Httpentity<string> (body, headers); String result = Resttemplate.postforobject (Geteurkaclient ("Hello-module"), Formentity,string.class); return 0;}
public string Geteurkaclient (string end) {Instanceinfo instance = Discoveryclient.getnextserverfromeureka ("Smartho Me-phihome ", false); return Instance.gethomepageurl () + END;}


This makes it possible to call each other between applications


This article is from the "www.bogo.com" blog, make sure to keep this source http://483181.blog.51cto.com/473181/1954798

Using Resttemplate in Springboot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.