Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems like all You need is to create the Spring <code>ApplicationContext</code> properly. I think it's possible <strong>without</strong> classpath mingling. What matters most are the locations of the Spring configuration files <strong>within</strong> the classpath. So put all Your plugin jar's into <code>WEB-INF/lib</code> and read on.</p> <p>Let's start with the core module. We'll make it to create it's <code>ApplicationContext</code> from files located at <code>classpath*:META-INF/spring/*-corecontext.xml</code>.</p> <p>Now we'll make all plugins to have their config files elsewhere. I.e. 'myplugin1' will have its config location like this: <code>classpath*:META-INF/spring/*-myplugin1context.xml</code>. And <code>anotherplugin</code> will have the configs at <code>classpath*:META-INF/spring/*-anotherplugincontext.xml</code>.</p> <p>What You see is <strong>a convension</strong>. You can also use subdirectiries if You like:</p> <ul> <li>core: <code>classpath*:META-INF/spring/core/*.xml</code></li> <li>myplugin1: <code>classpath*:META-INF/spring/myplugin1/*.xml</code></li> <li>anotherplugin: <code>classpath*:META-INF/spring/anotherplugin/*.xml</code></li> </ul> <p>What matters is that the locations have to be <strong>disjoint</strong>.</p> <p>All that remains is to pass the right locations to the <code>ApplicationContext</code> creator. For web applications the right place for this would be to extend the <code>ContextLoaderListener</code> and override the method <code>customizeContext(ServletContext, ConfigurableWebApplicationContext)</code>.</p> <p>All that remains is to read Your config file (its location can be passed as servlet init parameter). Than You need to construct the list of config locations:</p> <pre><code>String locationPrefix = "classpath*:META-INF/spring/"; String locationSiffix = "/*.xml"; List&lt;String&gt; configLocations = new ArrayList&lt;String&gt;(); configLocations.add(locationPrefix + "core" + locationSiffix); List&lt;String&gt; pluginsTurnedOn = getPluginsTurnedOnFromConfiguration(); for (String pluginName : pluginsTurnedOn) { configLocations.add(locationPrefix + pluginName + locationSiffix); } applicationContext.setConfigLocations(configLocations.toArray(new String[configLocations.size()])); </code></pre> <p>This way You can easily manage what is and what is not loaded into Spring <code>ApplicationContext</code>.</p> <p><strong>Update:</strong></p> <p>To make it work there's one more hidden assumption I made that I'm about to explain now. The <strong>base package</strong> of the core module and each plugin should also be <strong>disjoint</strong>. That is i.e.:</p> <ul> <li>com.mycompany.myapp.core</li> <li>com.mycompany.myapp.myplugin1</li> <li>com.mycompany.myapp.anotherplugin</li> </ul> <p>This way each module can use <code>&lt;context:componet-scan /&gt;</code> (on equivalent in JavaConfig) easily to add classpath scanning for <strong>it's own classes only</strong>. The core module <strong>should not</strong> contain any package scanning of any plugin packages. The <strong>plugins should extend configuration</strong> of <code>ApplicationContext</code> to add their own packages to classpath scanning.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload