Spring boot - Bean在自动装配依赖时没有找到诅咒

时间:2018-05-22 06:48:51

标签: spring-boot

我使用的是springboot 1.5.13

这是我的控制器类:

@RestController
@RequestMapping("/payment")
public class PaymentResource {

   @Autowired
   private UserService userService;

   @Autowired
   private UserPaymentService userPaymentService;

   @RequestMapping(value="/add", method=RequestMethod.POST)
   public ResponseEntity addNewCreditCardPost (
        @RequestBody UserPayment userPayment,
        Principal principal) {
      User user = userService.findByUsername(principal.getName());

      UserBilling userBilling = userPayment.getUserBilling();

      userService.updateUserBilling(userBilling, userPayment, user);

      return new ResponseEntity("Payment Added(Updated) Successfully!", HttpStatus.OK);
   }

   @RequestMapping(value="/remove", method=RequestMethod.POST)
   public ResponseEntity removePaymentPost(
        @RequestBody String id,
        Principal principal
        ){
// User user = userService.findByUsername(principal.getName());

      userPaymentService.removeById(Long.valueOf(id));

      return new ResponseEntity("Payment Removed Successfully!", HttpStatus.OK);
   }

   @RequestMapping(value="/setDefault", method=RequestMethod.POST)
   public ResponseEntity setDefaultPaymentPost(
        @RequestBody String id,
        Principal principal
        ){
      User user = userService.findByUsername(principal.getName());

      userService.setUserDefaultPayment(Long.parseLong(id), user);

      return new ResponseEntity("Payment Removed Successfully!", HttpStatus.OK);
   }

   @RequestMapping("/getUserPaymentList")
   public List<UserPayment> getUserPaymentList(
        Principal principal
        ){
      User user = userService.findByUsername(principal.getName());

      List<UserPayment> userPaymentList = user.getUserPaymentList();

      return userPaymentList;
   }

}

这是我的界面:

public interface UserPaymentService {

   UserPayment findById(Long id);

   void removeById(Long id);
}

我在尝试运行程序时遇到此问题:

***************************
APPLICATION FAILED TO START
***************************
Description: Field userPaymentService in com.sovimal.bookstore.resource.PaymentResource required a bean of type 'com.sovimal.bookstore.service.UserPaymentService' that could not be found.

Action:
Consider defining a bean of type 'com.sovimal.bookstore.service.UserPaymentService' in your configuration.

1 个答案:

答案 0 :(得分:0)

请在服务类中添加@Service annotaion,然后重试。

@Service
public interface UserPaymentService {

   UserPayment findById(Long id);

   void removeById(Long id);
}