Remove @Bean RestTemplate
(If users need one they can add it themselves) Fixes gh-239
This commit is contained in:
@@ -36,8 +36,8 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public class SampleController
|
||||
implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Log log = LogFactory.getLog(SampleController.class);
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@@ -47,16 +47,16 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private SpanAccessor accessor;
|
||||
@Autowired
|
||||
private SampleBackground controller;
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
private Random random = new Random();
|
||||
private int port;
|
||||
|
||||
@RequestMapping("/")
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/hi2", String.class);
|
||||
String s = this.restTemplate
|
||||
.getForObject("http://localhost:" + this.port + "/hi2", String.class);
|
||||
return "hi/" + s;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
public String call() throws Exception {
|
||||
int millis = SampleController.this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis));
|
||||
SampleController.this.tracer.addTag("callable-sleep-millis",
|
||||
String.valueOf(millis));
|
||||
Span currentSpan = SampleController.this.accessor.getCurrentSpan();
|
||||
return "async hi: " + currentSpan;
|
||||
}
|
||||
@@ -97,8 +98,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
String s = this.restTemplate
|
||||
.getForObject("http://localhost:" + this.port + "/call", String.class);
|
||||
this.tracer.close(span);
|
||||
return "traced/" + s;
|
||||
}
|
||||
@@ -110,8 +111,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
+ "/call", String.class);
|
||||
String s = this.restTemplate
|
||||
.getForObject("http://localhost:" + this.port + "/call", String.class);
|
||||
return "start/" + s;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -32,6 +33,11 @@ public class SampleSleuthApplication {
|
||||
|
||||
public static final String CLIENT_NAME = "testApp";
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SampleController sampleController() {
|
||||
return new SampleController();
|
||||
|
||||
Reference in New Issue
Block a user