Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
使用Spring Boot一次性读取多个属性文件?_Spring_Spring Boot_Spring Rest_Api Versioning - Fatal编程技术网

使用Spring Boot一次性读取多个属性文件?

使用Spring Boot一次性读取多个属性文件?,spring,spring-boot,spring-rest,api-versioning,Spring,Spring Boot,Spring Rest,Api Versioning,我多次浏览了link:和其他相关链接,但它仍然不起作用 我使用的是SpringBoot和SpringRest示例。链接问题: 我创建了类似这样的映射,只需阅读映射即可 get.customers={GET: '/app-data/customers', VERSION: 'v1'} post.customers={POST: '/app-data/customers', VERSION: 'v1'} get.customers.custId={GET: '/app-data/customers/

我多次浏览了link:和其他相关链接,但它仍然不起作用

我使用的是SpringBoot和SpringRest示例。链接问题:

我创建了类似这样的映射,只需阅读映射即可

get.customers={GET: '/app-data/customers', VERSION: 'v1'}
post.customers={POST: '/app-data/customers', VERSION: 'v1'}
get.customers.custId={GET: '/app-data/customers/{custId}', VERSION: 'v2'}
代码:

代码:

@组件
@配置属性
@PropertySource(“类路径:restendpoint.properties”)
公共类优先级处理器{
private final Map priorityMap=new HashMap();
公共映射getPriority(){
返回优先映射;
}
}

代码:

我建议以下实现:

@ConfigurationProperties(prefix="request")
public class ConfigurationProps {
    private List<Mapping> mapping;

    public List<Mapping> getMapping() {
        return mapping;
    }

    public void setMapping(List<Mapping> mapping) {
        this.mapping = mapping;
    }
}
在配置或spring引导应用程序类(具有main方法的类)上:
@EnableConfigurationProperties(ConfigurationProps.class)

在属性文件中,输入:

request.mapping[0].method=get
request.mapping[0].url=/customers
request.mapping[0].version=1

request.mapping[1].method=post
request.mapping[1].url=/students
request.mapping[1].version=2
在Filter中(我假设您遵循了链接问题中的建议):

@组件
@订单(1)
公共类LatestVersionFilter实现筛选器{
私有列表映射;
公共最新版本过滤器(配置道具道具){
this.mappings=props.getMapping();
}
}

我建议以下实施方式:

@ConfigurationProperties(prefix="request")
public class ConfigurationProps {
    private List<Mapping> mapping;

    public List<Mapping> getMapping() {
        return mapping;
    }

    public void setMapping(List<Mapping> mapping) {
        this.mapping = mapping;
    }
}
在配置或spring引导应用程序类(具有main方法的类)上:
@EnableConfigurationProperties(ConfigurationProps.class)

在属性文件中,输入:

request.mapping[0].method=get
request.mapping[0].url=/customers
request.mapping[0].version=1

request.mapping[1].method=post
request.mapping[1].url=/students
request.mapping[1].version=2
在Filter中(我假设您遵循了链接问题中的建议):

@组件
@订单(1)
公共类LatestVersionFilter实现筛选器{
私有列表映射;
公共最新版本过滤器(配置道具道具){
this.mappings=props.getMapping();
}
}

BTW,从你想达到的目标——考虑使用像Spring Cloud Gateway项目、ZUUL 2甚至NGIX之类的东西。如果你有多个微服务,它们有一个共同的入口点(一个网关)——也许你可以在那里做任何事情……我同意,谢谢你提供的伟大解决方案。如果不使用微服务体系结构,这是实现它的最佳方式。然而,我被困在这里发布的小问题:BTW,从你想要达到的——考虑使用Spring云网关项目,ZUUL 2甚至NGIX之类的东西。如果你有多个微服务,它们有一个共同的入口点(一个网关)——也许你可以在那里做任何事情……我同意,谢谢你提供的伟大解决方案。如果不使用微服务体系结构,这是实现它的最佳方式。然而,我被贴在这里的小问题困扰着:
request.mapping[0].method=get
request.mapping[0].url=/customers
request.mapping[0].version=1

request.mapping[1].method=post
request.mapping[1].url=/students
request.mapping[1].version=2
    @Component
    @Order(1)
    public class LatestVersionFilter implements Filter {

       private List<Mapping> mappings;

       public LatestVersionFilter(ConfigurationProps props) {
          this.mappings = props.getMapping();
       }
    }