我有一些为 Spring Boot 应用程序编写的假客户端
这是我的代码
首先这是一个 Controller ,我在其中使用我的 feign 客户端
package demo.notification;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import demo.shema.Feign.NotifFeignClient;
import demo.shema.dto.NotificationDTO;
@RestController
@RequestMapping(NotificationRestMediator.API)
public class NotificationRestMediator {
public static final String API ="notif";
@Autowired
private NotifFeignClient notifFeignClient;
@GetMapping
List<NotificationDTO> getAllNotifications(){
return notifFeignClient.getAll();
}
}
那么我的假客户端如下
package demo.shema.Feign;
import java.util.List;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import demo.shema.dto.NotificationDTO;
@FeignClient("Notification")
public interface NotifFeignClient {
public static final String NOTIF = "notif";
@GetMapping(NOTIF)
List<NotificationDTO> getAll();
@PutMapping(NOTIF)
Boolean setNotif(@RequestBody NotificationDTO notif,@RequestParam String principal);
@PostMapping(NOTIF)
NotificationDTO createNotif(@RequestBody NotificationDTO notif,@RequestParam String principal);
@DeleteMapping(NOTIF)
Boolean deleteNotif(@RequestParam Long notifID,@RequestParam String principal);
}
我的 feign 配置位于主类上,使用注释和另一个配置类,如下所示
@SpringBootApplication
@EnableOAuth2Sso
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { AppClientFeign.class })
@RibbonClients({ @RibbonClient(name = "COMPONENTS"), @RibbonClient(name = "USERS-MANAGER") })
@ComponentScan(basePackageClasses = { ClientApplication.class , AppClientFeign.class })
那么类配置是
@Configuration
@EnableFeignClients
@ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})
public class FeignConfig {
}
那么异常错误详细信息如下
Error creating bean with name 'notificationRestMediator': Unsatisfied dependency expressed through field 'notifFeignClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demo.shema.Feign.NotifFeignClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 1
要做什么?
最佳答案
这是一个错误 here ,正如你所说,对于最新版本不需要指定值,但对于旧版本需要指定值
@PutMapping(NOTIF)
Boolean setNotif(@RequestBody NotificationDTO notif,@RequestParam("principal") String principal);
关于java - 运行我的 Spring Boot 应用程序时出现 Feign UnsatisfiedDependecyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54428832/