限制每个资源的最大文件大小

问题描述 投票:0回答:1

我正在使用 Apache-cxf (JAX-RS) 和 spring 框架。我的 beans.xml 中有以下示例代码。

    <jaxrs:server id="services" address="${http.server}">
        <jaxrs:properties>
            <entry key="attachment-max-size" value="1024" />
        </jaxrs:properties>
        <jaxrs:serviceBeans>
            <bean id="mainResource" class="com.abc.rest.api.MainResource">
            <lookup-method name="createEmployeeCollectionResource"
                    bean="employeeCollectionResource" />
            </bean>
        ...
        ...other beans
        ...
        </jaxrs:serviceBeans>
    </jaxrs:server>

我还有以下代码

<bean id="employeeCollectionResource"
    class="com.abc.rest.services.EmployeeCollectionResourceImpl">
    <lookup-method name="createNewEmployeeResource" bean="employeeResource" />
</bean>
<bean id="employeeResource" scope="prototype"
    class="com.abc.rest.services.EmployeeResourceImpl">
</bean>

我已将所有服务的上传期间最大文件大小设置为 1KB。

如何限制

attachment-max-size
特别适用于少数豆类?示例 - 5MB 用于少数豆子,2MB 用于其他少数豆等

java spring apache cxf jax-rs
1个回答
3
投票

您必须将端点/资源组织在单独的

<jaxrs:server >
标签中,并使用自己的附件大小设置:

<jaxrs:server id="services">
    <jaxrs:properties>
        <entry key="attachment-max-size" value="1024" />
    </jaxrs:properties>
    ....
</jaxrs:server>


<jaxrs:server id="largeFileServices">
    <jaxrs:properties>
        <entry key="attachment-max-size" value="1000000" />
    </jaxrs:properties>
    ....
</jaxrs:server>

https://cxf.apache.org/docs/jax-rs-multiparts.html

© www.soinside.com 2019 - 2024. All rights reserved.