java - 通过网络公开 jar 资源

标签 java spring resources jar

我有一个网络服务(使用 Spring-WS)。

我有一个包含多个模式(schema1.xsd、schema2.xsd 和 schema3.xsd)的 jar,我将它们包含在我的 Web 服务中。

有没有办法在我的网络服务 wep 应用程序中通过 servlet 公开 jar 中的模式?

我的 Spring MessageDispatcherServlet 映射到/ws/

我希望我的模式公开给 /schemas/schema1.xsd /schemas/schema2.xsd 等等。

我知道如何使用 servlet 来完成它,但它太冗长了,必须有更好的方法。

我的想法是有一个 servlet 过滤器,所有命中/schemas/的东西都检查它是否在我的允许资源列表中并显示它。

这必须是与服务器无关的解决方案。 (例如 http://tuckey.org/urlrewrite/ 将不起作用)。

谢谢。

最佳答案

又是我!看到对您的原始问题的评论后,我想我会提供一个替代解决方案。

如果我理解您的问题,您似乎有一个 WSDL(由 Spring-WS 生成),其中包含对各种模式的引用。当客户端尝试遵循这些模式引用时,它会失败,因为没有这样的资源。

Spring-WS 提供了一个很好的方法来解决这个问题,这在 section on WSDL exposure 中有描述。 :

If you want to use multiple schemas, either by includes or imports, you might want to use the CommonsXsdSchemaCollection, and refer to that from the DefaultWsdl11Definition, like so:

<bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
    <property name="xsds">
        <list>
            <value>classpath:/path/to/schema1.xsd</value>
            <value>classpath:/path/to/schema2.xsd</value>
        </list>
    </property>
    <property name="inline" value="true"/>
</bean>

When the inline property is enabled, it follows all XSD imports and includes, and inlines them in the WSDL. This greatly simplifies the deloyment of the schemas, which still making it possible to edit them separately.

因此,您得到的是一个生成的 WSDL,其中包含所有内联的引用模式,因此没有供客户端遵循的引用。它非常灵活,意味着您不必单独公开您的架构文件。

关于java - 通过网络公开 jar 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587526/

相关文章:

silverlight - Silverlight中使用嵌入式资源(四)——其他文化不编译

json - REST 资源的 JSON 表示是否应该使用相关资源的 URI?

java - 为什么像 List/Map/Set.of(...) 或 Arrays.asList(...) 这样的方法会返回不可变列表?

java - 网站不加载资源

java - "is an unknown property": custom properties in Spring's application. 属性

java - 如何在java spring boot中记录JSON对象?

ruby-on-rails - 功能测试中的路由问题

java - 在 Ubuntu 上运行 SimGrid-Java 示例时出现 UnsatisfiedLinkError

java - 从 Spring Boot JSON 响应中删除 "_embedded"和 "_links"

java - 将 EJB3 与 Spring 集成