Mohammed Housseyn Taleb
Mohammed Housseyn Taleb

Reputation: 1828

Feign UnsatisfiedDependecyException when running my spring boot app

I have some feign clients that I writed for my spring boot app

Here is my code

First here is a controller that where I use my feign client

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();
    }
}

then My feign client is as below

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);

}

My feign configuration is on the main class using annotations and another config class as below

@SpringBootApplication
@EnableOAuth2Sso
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { AppClientFeign.class })
@RibbonClients({ @RibbonClient(name = "COMPONENTS"), @RibbonClient(name = "USERS-MANAGER") })
@ComponentScan(basePackageClasses = { ClientApplication.class , AppClientFeign.class })

then the class config is

@Configuration
@EnableFeignClients
@ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})
public class FeignConfig {

}

then the exception error detail is as below

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

What to do ?

Upvotes: 1

Views: 2080

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 40048

This is a bug here, as you said for latest version don't need to specify value, but for older versions need to specify the value

@PutMapping(NOTIF)
Boolean setNotif(@RequestBody NotificationDTO notif,@RequestParam("principal") String principal);

Upvotes: 2

Related Questions