【发布时间】:2018-06-26 01:54:40
【问题描述】:
嗨,我有这个项目在 Spring Boot 上运行。当我尝试运行时,它给了我以下错误:
说明:
com.mycompany.microservice.myproject.bot.controller.BotCommandController 中的字段 clientCredentialsApi 需要找不到类型为“org.springframework.web.client.RestOperations”的 bean。
行动:
考虑在你的配置中定义一个“org.springframework.web.client.RestOperations”类型的bean。
这是我的代码:
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);
}
}
这里是控制器:
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的代码是什么?尝试在您的班级添加@Service或@Component。希望对您有所帮助。 -
我更新了代码
-
需要添加RestOperations的代码
标签: java spring spring-boot