0

I am currently doing a modular web application from scratch and I am using Spring 4. The main problem is that I want that each module will register to the core module so that their presence will be known.

Here is the breakdown of the modules

  • Base Module: module registration interface & implementation
  • Module 1 which will need to register to the Base Module.
  • Module 2 which also will need to register to the Base Modules

Module 1 (and other modules) are all optional.

I am on quite a tight schedule so as much as possible, I want to use Spring IoC only. Thanks.

EDIT: The modules do not need to be dynamically registered at runtime.

Robby F
  • 397
  • 1
  • 2
  • 13

1 Answers1

1

My approach to this issue is to declare a specific package (com.example.myapp.config) for configuration classes. My core code component-scans that config package, and each module has a configuration class in that package that registers that module's resources. This usually involves a component scan scoped to that particular module's base package, a handful of beans, and perhaps some additional wiring logic such as adding property sources.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • Unless these modules need to be dynamically "registered" at runtime. – Andrei Stefan Jun 17 '14 at 15:12
  • @AndreiStefan The problem is terribly underspecified, but all this requires is that the modules be on the classpath. If the OP needs dynamic addition and removal, which I didn't get from his question, we're well into OSGi territory. – chrylis -cautiouslyoptimistic- Jun 17 '14 at 15:30
  • :-) problem solved. The OP updated the question. – Andrei Stefan Jun 17 '14 at 15:36
  • Seems like this is the way to go. Thanks! :) – Robby F Jun 17 '14 at 15:38
  • This could work put be wary when using component scanning and jars containing modules. It will require you to unpack the jars since the scan expects classes be exist inside a directory structure. – Bart Jun 17 '14 at 15:39
  • @Bart ...what are you talking about? – chrylis -cautiouslyoptimistic- Jun 17 '14 at 15:47
  • Basically what I meant is that you cannot component scan annotated classes inside a jar. If one would package modules in jars. – Bart Jun 17 '14 at 15:50
  • @Bart That's completely incorrect. – chrylis -cautiouslyoptimistic- Jun 17 '14 at 15:55
  • That is interesting... I tried exactly that a few days ago and it wouldn't work unless jars where unpacked. So you're saying it's possible? If so, I would be dying to know :-) – Bart Jun 17 '14 at 16:00
  • @Bart How do you create the jar file? Does [this](http://stackoverflow.com/questions/1242656/spring-annotation-based-controllers-not-working-if-it-is-inside-jar-file#1242658) answer solve your problem? – Shinichi Kai Jun 17 '14 at 17:29
  • @ShinichiKai It's a packaged maven module that I imported into a project. I read the answer but it does not provide the answer for me. I'm using IDEA but even when deploying the project on Tomcat the classes can't be found through scanning when existing in a jar. – Bart Jun 17 '14 at 19:56
  • @Bart You have some other major problem. Perhaps ask a question about it. – chrylis -cautiouslyoptimistic- Jun 17 '14 at 20:52
  • @chrylis Yes, you are right. I managed to get it working in a very simple project. Thank you for pointing out my mistake. Now I can work toward a solution. – Bart Jun 17 '14 at 22:12