Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @FeignClient可以扩展并@RestController实现一个通用的、完全注释的接口吗?_Java_Spring_Spring Boot_Spring Restcontroller_Netflix Feign - Fatal编程技术网

Java @FeignClient可以扩展并@RestController实现一个通用的、完全注释的接口吗?

Java @FeignClient可以扩展并@RestController实现一个通用的、完全注释的接口吗?,java,spring,spring-boot,spring-restcontroller,netflix-feign,Java,Spring,Spring Boot,Spring Restcontroller,Netflix Feign,我希望一个外部客户机使用一个Spring引导控制器,并且我希望它们之间的契约尽可能在公共接口中指定 方法的接口如下所示: @RequestMapping public interface RuleManager { @RequestMapping(value = "/addRule", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"}) @R

我希望一个外部客户机使用一个Spring引导控制器,并且我希望它们之间的契约尽可能在公共接口中指定

方法的接口如下所示:

@RequestMapping
public interface RuleManager {

    @RequestMapping(value = "/addRule", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"})
    @ResponseBody Rule addRule(@RequestBody Rule rule);
}
该外国客户看起来像:

@FeignClient(url = "http://localhost:8080")
public interface RuleManagerClient extends RuleManager { }
和Spring引导控制器:

@RestController
public class RuleManagerService implements RuleManager {

    @Override
    @Transactional
    public Rule addRule(@RequestBody Rule rule) {
        return rule;
    }
}
我不必在两个地方指定@RequestMapping,这很好,但不幸的是,我似乎必须指定@RequestBody两次。当控制器或共享接口中省略@RequestBody时,将实例化规则对象,但所有成员都设置为null

有办法解决这个问题吗?也许这是在一个更新的版本中解决的?我的依赖项包括:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-feign</artifactId>
        <exclusions>
            <exclusion>
                <groupId>com.netflix.feign</groupId>
                <artifactId>feign-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.netflix.feign</groupId>
        <artifactId>feign-core</artifactId>
        <version>8.14.3</version>
    </dependency>

org.springframework.cloud

感谢您的帮助。

显然这是可行的--@RequestBody只需出现在共享界面中。问题是我在application.properties中为控制器设置了以下属性,但没有为客户端设置:

spring.jackson.property-naming-strategy=CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES

这就是为什么该对象在服务器端实例化,但所有成员都为空——实际上,错误的属性是通过网络发送的,例如“ruleName”而不是预期的“rule_name”。

我也看到了这一点,这使得这一技术似乎在大部分情况下都有效:(但这里没有提到@RequestBody)