0
我的主要入門級與「無消息」從Spring應用程序
package com.project.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class HelloworldClientApplication {
public static void main(String[] args) {
SpringApplication.run(HelloworldClientApplication.class, args);
}
}
我的資源文件
package com.project.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
*
* @author Wasp Networks
*/
@RestController
@RequestMapping("/rest/client/helloworld")
public class HelloResources {
@Autowired
private RestTemplate restTemplate;
@GetMapping
public String Entry(){
String url = "http://helloworld-server/rest/server/helloworld";
return restTemplate.getForObject(url, String.class);
}
@RequestMapping("/")
public String Main(){
return "Helloworld client!.";
}
}
我的配置類
package com.project.configuration;
/**
*
* @author Wasp Networks
*/
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class Configure {
@LoadBalanced
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
如果你的春天代碼結構錯誤頁面是這樣的,你嘗試運行該應用程序,不要驚訝,以獲得錯誤的Web控制檯。
對不起傢伙對我的英語不好....