无法从浏览器中部署的war访问enunciate生成的doc

时间:2014-04-29 08:43:43

标签: java spring enunciate

我正在使用enunciate生成我的其余api文档,最初它工作正常,除非我在项目中添加了spring依赖项。
我现在的pom:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-webmvc</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>  
            <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.18.1</version>
    </dependency>  
    <dependency>
        <groupId>org.codehaus.enunciate</groupId>
        <artifactId>enunciate-rt</artifactId>
        <version>1.26</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>src/main/webapp</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>index.html</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.enunciate</groupId>
            <artifactId>maven-enunciate-plugin</artifactId>
            <version>1.26</version>
            <configuration>
                <configFile>src/main/resources/enunciate.xml</configFile>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.enunciate</groupId>
                                    <artifactId>maven-enunciate-plugin</artifactId>
                                    <versionRange>[1.26,)</versionRange>
                                    <goals>
                                        <goal>assemble</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>  

以上配置是在生成战争的api目录中生成文档。我有以下 enunciate.xml 配置:

<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
<webapp mergeWebXML="../webapp/WEB-INF/web.xml"></webapp>
<modules>
    <docs splashPackage="com.pack.resources" docsDir="api" title="My API" copyright="amg" includeDefaultDownloads="true" />
    <jersey useSubcontext="true" />
</modules>

文档生成正确,但是当我尝试点击http://localhost:8080/amg-web/api/index.html时,它会给出404响应。我在tomcat webapp中检查了提取的war,其中api目录已成功生成所有必需的文件,但仍然无法从浏览器中的已部署应用程序访问它。请帮忙。

1 个答案:

答案 0 :(得分:0)

我想我找到了解决方案。它可能与我使用的较旧版本的enunciate相关,即v1.26或我的<url-pattern>中有多个web.xml
我添加了额外的servlet mapping并且它有效..

    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>  

其中/api/是我的api文档的路径。我仍然不明白为什么有必要这样做。如果有人向我解释这一点会很棒。