Не удалось Autowire Field: Resttemplate в Spring Boot ApplicationJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Не удалось Autowire Field: Resttemplate в Spring Boot Application

Сообщение Anonymous »

Я получаю ниже исключения при запуске Spring Boot приложения во время запуска:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'testController':
Injection of autowired dependencies failed;
nested exception is
org.springframework.beans.factory.BeanCreationException:
Could not autowire field:
private org.springframework.web.client.RestTemplate
com.micro.test.controller.TestController.restTemplate;
nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type
[org.springframework.web.client.RestTemplate]
found for dependency: expected at least 1 bean which qualifies
as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Я автоматически разворачивается Resttemplate в моем TestController. Я использую Maven для управления зависимостями.
testmicroserviceApplication.javaобразного/>>>>package com.micro.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TestMicroServiceApplication {

public static void main(String[] args) {
SpringApplication.run(TestMicroServiceApplication.class, args);
}
}

testcontroller.java
package com.micro.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

@Autowired
private RestTemplate restTemplate;

@RequestMapping(value="/micro/order/{id}",
method=RequestMethod.GET,
produces=MediaType.ALL_VALUE)
public String placeOrder(@PathVariable("id") int customerId){

System.out.println("Hit ===> PlaceOrder");

Object[] customerJson = restTemplate.getForObject("http://localhost:8080/micro/customers", Object[].class);

System.out.println(customerJson.toString());

return "false";
}

}

pom.xml


4.0.0

com.micro.test
Test-MicroService
0.0.1-SNAPSHOT
jar

Test-MicroService
Demo project for Spring Boot


org.springframework.boot
spring-boot-starter-parent
1.3.3.RELEASE




UTF-8
1.8




org.springframework.boot
spring-boot-starter-web



org.springframework.boot
spring-boot-starter-test
test






org.springframework.boot
spring-boot-maven-plugin







Подробнее здесь: https://stackoverflow.com/questions/361 ... pplication
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»