Question

I am using enunciate to generate my rest api documentation, initially it was working fine unless I added spring dependency to my project.
My current 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>  

above configuration is generating docs in api directory under war generated. I have following enunciate.xml configuration:

<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>

docs are generated properly, but when I am trying to hit http://localhost:8080/amg-web/api/index.html its giving 404 response.! I checked with extracted war in tomcat webapp where api directory is successfully generated with all the required files, but still not able to access it from deployed app in browser. please help.

Was it helpful?

Solution

I think I found the solution. It may be related with either older version of enunciate which I am using i.e. v1.26 or there are multiple <url-pattern> in my web.xml.
I added additional servlet mapping and it worked..

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

where /api/ is path to my api documentation. I still did not get why there necessity of this. It would be great if someone explain this to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top