当前位置:   article > 正文

调用post请求方式的feign接口怎么传递多个参数,包含对象和字符串_feign下post请求传递参数

feign下post请求传递参数

今天尝试把自己原来的项目上的权限管理相关的类抽离开来,并建立一个统一的权限管理平台,然后项目中要用到的权限相关资源通过feigin请求权限平台的对应接口获取。

现在有一个需求,页面上有一个一键获取资源权限的按钮,点击一下,在后台完成控制器接口的扫描,自动添加对应资源(先从数据库删除原来的资源)。

这个接口的代码

  1. package cn.edu.sgu.www.mhxysy.service.system.impl;
  2. import cn.edu.sgu.www.mhxysy.base.Pager;
  3. import cn.edu.sgu.www.mhxysy.entity.system.Permission;
  4. import cn.edu.sgu.www.mhxysy.mapper.system.PermissionMapper;
  5. import cn.edu.sgu.www.mhxysy.pager.system.PermissionPager;
  6. import cn.edu.sgu.www.mhxysy.service.system.PermissionService;
  7. import cn.edu.sgu.www.mhxysy.util.ResourceScanner;
  8. import cn.edu.sgu.www.mhxysy.util.StringUtils;
  9. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.stereotype.Service;
  13. import java.util.List;
  14. /**
  15. * @author heyunlin
  16. * @version 1.0
  17. */
  18. @Service
  19. public class PermissionServiceImpl implements PermissionService {
  20. @Value("${spring.application.name}")
  21. private String SERVICE_NAME;
  22. private final PermissionMapper mapper;
  23. private final ResourceScanner resourceScanner;
  24. public PermissionServiceImpl(PermissionMapper mapper, ResourceScanner resourceScanner) {
  25. this.mapper = mapper;
  26. this.resourceScanner = resourceScanner;
  27. }
  28. @Override
  29. public void init() throws ClassNotFoundException {
  30. // 删除指定服务的权限
  31. mapper.deleteByService(SERVICE_NAME);
  32. // 扫描路径
  33. String basePackage = "cn.edu.sgu.www.mhxysy.controller";
  34. // 获取扫描结果
  35. List<Permission> resources = resourceScanner.scan(basePackage);
  36. // 保存资源到数据库
  37. for (Permission permission : resources) {
  38. if (permission.getName() != null) {
  39. mapper.insert(permission);
  40. }
  41. }
  42. }
  43. }

ResourceScanner这个类负责扫描controller包下的所有控制器的信息并封装成一个个Permission。

扫描的操作是在当前项目下完成,权限平台的接口只需要完成权限的删除和新权限的添加。

重构后的代码:

  1. package cn.edu.sgu.www.mhxysy.service.system.impl;
  2. import cn.edu.sgu.www.mhxysy.base.Pager;
  3. import cn.edu.sgu.www.mhxysy.entity.system.Permission;
  4. import cn.edu.sgu.www.mhxysy.feign.FeignService;
  5. import cn.edu.sgu.www.mhxysy.mapper.system.PermissionMapper;
  6. import cn.edu.sgu.www.mhxysy.pager.system.PermissionPager;
  7. import cn.edu.sgu.www.mhxysy.service.system.PermissionService;
  8. import cn.edu.sgu.www.mhxysy.util.ResourceScanner;
  9. import cn.edu.sgu.www.mhxysy.util.StringUtils;
  10. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  11. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Service;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * @author heyunlin
  19. * @version 1.0
  20. */
  21. @Service
  22. public class PermissionServiceImpl implements PermissionService {
  23. @Value("${spring.application.name}")
  24. private String SERVICE_NAME;
  25. private final FeignService feignService;
  26. private final ResourceScanner resourceScanner;
  27. private final PermissionMapper permissionMapper;
  28. public PermissionServiceImpl(
  29. FeignService feignService,
  30. ResourceScanner resourceScanner,
  31. PermissionMapper permissionMapper
  32. ) {
  33. this.feignService = feignService;
  34. this.permissionMapper = permissionMapper;
  35. this.resourceScanner = resourceScanner;
  36. }
  37. @Override
  38. public void init() throws ClassNotFoundException {
  39. // 删除指定服务的权限
  40. permissionMapper.deleteByService(SERVICE_NAME);
  41. // 扫描路径
  42. String basePackage = "cn.edu.sgu.www.mhxysy.controller";
  43. // 获取扫描结果
  44. List<Permission> resources = resourceScanner.scan(basePackage);
  45. feignService.init(SERVICE_NAME, resources);
  46. }
  47. }

feign接口

  1. package cn.edu.sgu.www.mhxysy.feign;
  2. import cn.edu.sgu.www.mhxysy.component.MenuTree;
  3. import cn.edu.sgu.www.mhxysy.entity.system.Permission;
  4. import org.springframework.cloud.openfeign.FeignClient;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.RequestParam;
  8. import java.util.List;
  9. import java.util.Map;
  10. /**
  11. * @author heyunlin
  12. * @version 1.0
  13. */
  14. @FeignClient(name = "authority", fallback = FeignFallback.class)
  15. public interface FeignService {
  16. @RequestMapping(value = "/menu/listTree", method = RequestMethod.GET)
  17. Map<String, List<MenuTree>> listTree(@RequestParam("userId") String userId);
  18. @RequestMapping(value = "/permission/init", method = RequestMethod.POST)
  19. void init(String service, List<Permission> permissions);
  20. }

这里直接通过post请求传递两个参数,权限平台对应的接口代码如下

  1. package cn.edu.sgu.www.authority.controller;
  2. import cn.edu.sgu.www.authority.entity.Permission;
  3. import cn.edu.sgu.www.authority.pager.PermissionPager;
  4. import cn.edu.sgu.www.authority.restful.JsonResult;
  5. import cn.edu.sgu.www.authority.restful.PageResult;
  6. import cn.edu.sgu.www.authority.service.PermissionService;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.List;
  16. @RestController
  17. @Api(tags = "权限控制器类")
  18. @RequestMapping(path = "/permission", produces = "application/json;charset=utf-8")
  19. public class PermissionController {
  20. private final PermissionService permissionService;
  21. @Autowired
  22. public PermissionController(PermissionService service) {
  23. this.permissionService = service;
  24. }
  25. @ApiOperation("初始化权限列表")
  26. @RequestMapping(value = "/init", method = RequestMethod.POST)
  27. public JsonResult<Void> init(String service, List<Permission> permissions) throws ClassNotFoundException {
  28. permissionService.init(service, permissions);
  29. return JsonResult.success("权限列表初始化完成。");
  30. }
  31. }

业务层代码

  1. package cn.edu.sgu.www.authority.service.impl;
  2. import cn.edu.sgu.www.authority.base.Pager;
  3. import cn.edu.sgu.www.authority.entity.Permission;
  4. import cn.edu.sgu.www.authority.mapper.PermissionMapper;
  5. import cn.edu.sgu.www.authority.pager.PermissionPager;
  6. import cn.edu.sgu.www.authority.service.PermissionService;
  7. import cn.edu.sgu.www.authority.util.StringUtils;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import org.springframework.stereotype.Service;
  11. import java.util.List;
  12. /**
  13. * @author heyunlin
  14. * @version 1.0
  15. */
  16. @Service
  17. public class PermissionServiceImpl implements PermissionService {
  18. private final PermissionMapper mapper;
  19. public PermissionServiceImpl(PermissionMapper mapper) {
  20. this.mapper = mapper;
  21. }
  22. @Override
  23. public void init(String service, List<Permission> permissions) {
  24. // 删除指定服务的权限
  25. mapper.deleteByService(service);
  26. // 保存资源到数据库
  27. for (Permission permission : permissions) {
  28. if (permission.getName() != null) {
  29. mapper.insert(permission);
  30. }
  31. }
  32. }
  33. }

这个时候项目启动直接报错,看到这一堆报错是不是头都大了

  1. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shiroFilter' defined in class path resource [cn/edu/sgu/www/mhxysy/config/ShiroConfig.class]: Unsatisfied dependency expressed through method 'shiroFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityManager' defined in class path resource [cn/edu/sgu/www/mhxysy/config/ShiroConfig.class]: Unsatisfied dependency expressed through method 'securityManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRealm': Unsatisfied dependency expressed through field 'adminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisRepository' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\redis\RedisRepository.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  2. Warnings:
  3. -
  4. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  5. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  6. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  7. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  8. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  9. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  10. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  11. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  12. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  13. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  14. at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:241) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  15. at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:723) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  16. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  17. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  18. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  19. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  20. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  21. at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  22. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  23. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
  24. at cn.edu.sgu.www.mhxysy.MhxysyApplication.main(MhxysyApplication.java:26) [classes/:na]
  25. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityManager' defined in class path resource [cn/edu/sgu/www/mhxysy/config/ShiroConfig.class]: Unsatisfied dependency expressed through method 'securityManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRealm': Unsatisfied dependency expressed through field 'adminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisRepository' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\redis\RedisRepository.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  26. Warnings:
  27. -
  28. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  29. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  30. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  31. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  32. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  33. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  34. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  35. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  36. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  37. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  38. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  39. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  40. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  41. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  42. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  43. ... 20 common frames omitted
  44. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRealm': Unsatisfied dependency expressed through field 'adminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisRepository' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\redis\RedisRepository.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  45. Warnings:
  46. -
  47. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  48. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  49. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  50. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  51. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  52. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  53. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  54. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  55. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  56. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  57. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  58. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  59. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  60. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  61. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  62. ... 34 common frames omitted
  63. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisRepository' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\redis\RedisRepository.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  64. Warnings:
  65. -
  66. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  67. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  68. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  69. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  70. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  71. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  72. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  73. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  74. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  75. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  76. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  77. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  78. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  79. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  80. ... 48 common frames omitted
  81. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisRepository' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\redis\RedisRepository.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  82. Warnings:
  83. -
  84. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  85. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  86. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  87. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  88. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  89. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  90. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  91. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  92. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  93. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  94. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  95. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  96. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  97. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  98. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  99. ... 61 common frames omitted
  100. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'permissionServiceImpl' defined in file [D:\program\IdeaProjects\mhxysy\target\classes\cn\edu\sgu\www\mhxysy\service\system\impl\PermissionServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  101. Warnings:
  102. -
  103. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  104. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  105. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  106. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  107. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  108. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  109. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  110. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  111. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  112. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  113. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  114. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  115. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  116. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  117. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  118. ... 75 common frames omitted
  119. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.edu.sgu.www.mhxysy.feign.FeignService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  120. Warnings:
  121. -
  122. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  123. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  124. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  125. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  126. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  127. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  128. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  129. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  130. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  131. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  132. ... 89 common frames omitted
  133. Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  134. Warnings:
  135. -
  136. at feign.Util.checkState(Util.java:129) ~[feign-core-10.12.jar:na]
  137. at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:127) ~[feign-core-10.12.jar:na]
  138. at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:207) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  139. at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62) ~[feign-core-10.12.jar:na]
  140. at feign.hystrix.HystrixDelegatingContract.parseAndValidateMetadata(HystrixDelegatingContract.java:47) ~[feign-hystrix-10.12.jar:na]
  141. at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151) ~[feign-core-10.12.jar:na]
  142. at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49) ~[feign-core-10.12.jar:na]
  143. at feign.hystrix.HystrixFeign$Builder.target(HystrixFeign.java:63) ~[feign-hystrix-10.12.jar:na]
  144. at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallback(HystrixTargeter.java:74) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  145. at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:49) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  146. at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:352) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  147. at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:388) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  148. at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:361) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  149. at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:246) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  150. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1230) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  151. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1172) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  152. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  153. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  154. ... 98 common frames omitted

其实遇到这种情况,只需要找到问题的根源,也就是最后一个cause by

  1. Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract void cn.edu.sgu.www.mhxysy.feign.FeignService.init(java.lang.String,java.util.List)
  2. Warnings:
  3. -
  4. at feign.Util.checkState(Util.java:129) ~[feign-core-10.12.jar:na]
  5. at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:127) ~[feign-core-10.12.jar:na]
  6. at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:207) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  7. at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62) ~[feign-core-10.12.jar:na]
  8. at feign.hystrix.HystrixDelegatingContract.parseAndValidateMetadata(HystrixDelegatingContract.java:47) ~[feign-hystrix-10.12.jar:na]
  9. at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151) ~[feign-core-10.12.jar:na]
  10. at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49) ~[feign-core-10.12.jar:na]
  11. at feign.hystrix.HystrixFeign$Builder.target(HystrixFeign.java:63) ~[feign-hystrix-10.12.jar:na]
  12. at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallback(HystrixTargeter.java:74) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  13. at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:49) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  14. at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:352) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  15. at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:388) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  16. at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:361) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  17. at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:246) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
  18. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1230) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  19. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1172) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  20. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  21. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  22. ... 98 common frames omitted

这里的关键是这一句,方法有太多body参数,显然,post请求只能有一个请求体

Method has too many Body parameters

既然这样,我们就把两个参数封装成一个类不就行了:创建一个PermissionDTO类

  1. package cn.edu.sgu.www.mhxysy.dto.system;
  2. import cn.edu.sgu.www.mhxysy.entity.system.Permission;
  3. import lombok.Data;
  4. import java.util.List;
  5. /**
  6. * @author heyunlin
  7. * @version 1.0
  8. */
  9. @Data
  10. public class PermissionDTO {
  11. /**
  12. * 服务名称
  13. */
  14. String service;
  15. /**
  16. * 权限列表
  17. */
  18. List<Permission> permissions;
  19. }

修改之后的代码

  1. package cn.edu.sgu.www.mhxysy.service.system.impl;
  2. import cn.edu.sgu.www.mhxysy.base.Pager;
  3. import cn.edu.sgu.www.mhxysy.dto.system.PermissionDTO;
  4. import cn.edu.sgu.www.mhxysy.entity.system.Permission;
  5. import cn.edu.sgu.www.mhxysy.feign.FeignService;
  6. import cn.edu.sgu.www.mhxysy.mapper.system.PermissionMapper;
  7. import cn.edu.sgu.www.mhxysy.pager.system.PermissionPager;
  8. import cn.edu.sgu.www.mhxysy.service.system.PermissionService;
  9. import cn.edu.sgu.www.mhxysy.util.ResourceScanner;
  10. import cn.edu.sgu.www.mhxysy.util.StringUtils;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.stereotype.Service;
  15. import java.util.List;
  16. /**
  17. * @author heyunlin
  18. * @version 1.0
  19. */
  20. @Service
  21. public class PermissionServiceImpl implements PermissionService {
  22. @Value("${spring.application.name}")
  23. private String SERVICE_NAME;
  24. private final FeignService feignService;
  25. private final ResourceScanner resourceScanner;
  26. private final PermissionMapper permissionMapper;
  27. public PermissionServiceImpl(
  28. FeignService feignService,
  29. ResourceScanner resourceScanner,
  30. PermissionMapper permissionMapper
  31. ) {
  32. this.feignService = feignService;
  33. this.permissionMapper = permissionMapper;
  34. this.resourceScanner = resourceScanner;
  35. }
  36. @Override
  37. public void init() throws ClassNotFoundException {
  38. // 扫描路径
  39. String basePackage = "cn.edu.sgu.www.mhxysy.controller";
  40. // 获取扫描结果
  41. List<Permission> permissions = resourceScanner.scan(basePackage);
  42. PermissionDTO permissionDTO = new PermissionDTO();
  43. permissionDTO.setService(SERVICE_NAME);
  44. permissionDTO.setPermissions(permissions);
  45. feignService.init(permissionDTO);
  46. }
  47. }

 对应的feign接口参数修改为一个PermissionDTO对象

  1. package cn.edu.sgu.www.mhxysy.feign;
  2. import cn.edu.sgu.www.mhxysy.component.MenuTree;
  3. import cn.edu.sgu.www.mhxysy.dto.system.PermissionDTO;
  4. import org.springframework.cloud.openfeign.FeignClient;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.bind.annotation.RequestParam;
  8. import java.util.List;
  9. import java.util.Map;
  10. /**
  11. * @author heyunlin
  12. * @version 1.0
  13. */
  14. @FeignClient(name = "authority", fallback = FeignFallback.class)
  15. public interface FeignService {
  16. @RequestMapping(value = "/menu/listTree", method = RequestMethod.GET)
  17. Map<String, List<MenuTree>> listTree(@RequestParam("userId") String userId);
  18. @RequestMapping(value = "/permission/init", method = RequestMethod.POST)
  19. void init(PermissionDTO permissionDTO);
  20. }

权限平台的相关代码修改

控制器

@ApiOperation("初始化权限列表")
@RequestMapping(value = "/init", method = RequestMethod.POST)
public JsonResult<Void> init(PermissionDTO permissionDTO) throws ClassNotFoundException {
    permissionService.init(permissionDTO);

    return JsonResult.success("权限列表初始化完成。");
}

业务层

@Override
public void init(PermissionDTO permissionDTO) {
    String service = permissionDTO.getService();
    List<Permission> permissions = permissionDTO.getPermissions();

    // 删除指定服务的权限
    if (service != null) {
        mapper.deleteByService(service);
    }

    if (!permissions.isEmpty()) {
        // 保存到数据库
        for (Permission permission : permissions) {
            if (permission.getName() != null) {
                mapper.insert(permission);
            }
        }
    }
}

然后重新启动两个项目,启动没有报错了,然后再测试一下,点击初始化按钮,还是报错了

直接看权限平台的报错信息,NPE,没有获取到请求体中对应的参数

  1. java.lang.NullPointerException
  2. at cn.edu.sgu.www.authority.service.impl.PermissionServiceImpl.init(PermissionServiceImpl.java:104)
  3. at cn.edu.sgu.www.authority.controller.PermissionController.init(PermissionController.java:84)
  4. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  6. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  7. at java.lang.reflect.Method.invoke(Method.java:498)
  8. at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
  9. at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
  10. at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
  11. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
  12. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
  13. at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
  14. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
  15. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
  16. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
  17. at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
  18. at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
  19. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
  20. at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
  21. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
  22. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  23. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  24. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  25. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  26. at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
  27. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  28. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  29. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  30. at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
  31. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  32. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  33. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  34. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
  35. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
  36. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
  37. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  38. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
  39. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
  40. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
  41. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
  42. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  43. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
  44. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
  45. at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
  46. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
  47. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
  48. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
  49. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  50. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  51. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  52. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  53. at java.lang.Thread.run(Thread.java:748)

加上@RequestBody再试一下

这个时候报了一个不同的错,超过了hystrix超时时间

看一下权限平台的控制台,这时候参数都传过去,删除并插入773数据,说明这种方法可行。

好了,关于feign调用post请求的接口传递多个参数的介绍就分享到这里了,感兴趣的还可以试一下通过Map来传参

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/303023
推荐阅读
相关标签
  

闽ICP备14008679号