Skip to content
Advertisement

How to set JBoss Wildfly context root with XML-less Spring web application?

Having a Spring application with Maven where all the configuration is done in Java (all configuration previously stored in web.xml is now in annotated @Configuration files or in WebAppInitializer that extends AbstractAnnotationConfigDispatcherServletInitializer), how can I set the context root for my application in JBoss Wildfly? The app has no web.xml, nor jboss-web.xml .

When the app used XML configuration the context root was set in jboss-web.xml like this:

<jboss-web>  
    <context-root>mywebcontextroot</context-root>
</jboss-web>

Advertisement

Answer

JBoss wildfly defaults the context root to the name of the war file. Setting the name of the war file to the desired value (web context root) in Maven solves the issue:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <warName>mywebcontextroot</warName>
    </configuration>
</plugin>

More detailed answer by @Nikhil Bide can be found here.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement