Hi I have this project running on Spring boot. When I tried to run, it give me the following error:
Description:
Field clientCredentialsApi in com.mycompany.microservice.myproject.bot.controller.BotCommandController required a bean of type 'org.springframework.web.client.RestOperations' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.web.client.RestOperations' in your configuration.
Here is my Code:
Application.java
package com.mycompany.microservice.myproject
//some imports
@SpringBootApplication`
@ComponentScan(basePackages = "com.mycompany.*")
public class Application {
public static void main(String[] args) {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And here is the Controller:
BotCommandController.java
package com.mycompany.microservice.myproject.bot.controller;
//some imports
@RestController
@RequestMapping("/bot-command")
public class BotCommandController {
@Autowired
private RestOperations clientCredentialsApi;
@RequestMapping(value = "/sraix", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String sraixCommand(@RequestParam(name = "input", required = false) final String input,@RequestParam(name = "cs", required = false) final String cs) throws Exception {
final UserApiObject userApiObject = clientCredentialsApi.getForObject(env.getProperty("gms.location") + "/rest/user/" + userId, UserApiObject.class);
return userApiObject.getRole();
}
RestOperations
? Try to add@Service
or@Component
on your class.Hope to help you. – weaver Jun 26 '18 at 2:29