Version 1

    Why need Single Spring Application Context

    Here I would like to describe how I solved one of the issues through JBoss Modules.

    Often I thought how it is better to use Spring framework under JBoss/Wildfly. I believe that you also faced with situation when you need to use a few Spring Contexts in the different web applications, however you need to have single Spring Context that could contain common beans for others contexts. It would be great to load this guy only once, because I don't want to have any duplicates of beans.

    Spring Framework via JBoss Modules

    The best practice is using JBoss Modules instead of jars under WEB-INF/libs. I didn't find any plugins for gradle to be able to create a module.xml with all dependencies and jar files which are needed for this module.

    I have made that allows you to use something like this to define a JBoss Module for Spring Core:

    springCore {

      moduleName = 'org.springframework.core'

      resources = ["spring-core-${springVersion}.jar"]

      dependencies = ['javax.api',





    You can look at another link where collected modules to extract Spring and Apache Camel frameworks from web apps.


    Global Spring Context

    There is one more project that contains the JBoss Module named 'com.zhurlik' and a simple web application to show how it can be used.

    The main idea is based on

    It means that in your web applications you just need to do the following:

    • jboss-deployment-structure.xml
      <?xml version="1.0" encoding="UTF-8"?>




                <module name="com.zhurlik" />

                <module name="org.springframework.core" />

                <module name="org.springframework.web" />

                <module name="org.springframework.context" />

                <module name="org.springframework.context-support" />




    • web.xml













    After this when 'com.zhurlik' will be added as a module to you JBoss/WildFly server you will have only one instance of Spring Context that was loaded in the module.

    That's not a big deal to register its as JNDI resource as well.


    I tested it using two web applications and saw single context that was loaded once.

    I hope that should be interesting, please let me know if you have any questions.