Я получаю ниже исключения при запуске 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
Не удалось Autowire Field: Resttemplate в Spring Boot Application ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1758915400
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 для управления зависимостями.
[b] testmicroserviceApplication.java[/b]образного/>>>>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);
}
}
[b] testcontroller.java[/b]
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";
}
}
[b]pom.xml[/b]
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
Подробнее здесь: [url]https://stackoverflow.com/questions/36151421/could-not-autowire-fieldresttemplate-in-spring-boot-application[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия