Announcement Announcement Module
No announcement yet.
Using a SD-based library from various contexts Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using a SD-based library from various contexts

    I'm planning on creating a SD-based service layer packaged as its own jar that will be reused by other projects, including web projects (servlet) and traditional java programs run via main(). I was originally considering having the main project (the one reusing the service library) be responsible for any DI, Spring bootstrapping (if it chooses Spring), etc. However, projects using Spring Data require a minimal xml configuration file that must be used to bootstrap itself.

    Is there a typical pattern of structuring a reusable library that uses SD? Does the main project explicitly instantiate the ApplicationContext of the library project, or should the library project handle its own bootstrapping behind an init() method? (This is particularly unclear to me in a web context, where the initialization is declarative.)

    Thanks for any tips.


  • #2
    Use smart defaults and give the lib the opportunity to override them.


    • #3
      Thanks for the response. I'm not 100% clear on what you're saying. I assume you mean that the library should come with sensible defaults, and the application can override them.

      I'm also not clear on who should create the ApplicationContext(s). There are 3 options I see:

      1) The application creates one big ApplicationContext that sucks in bean definitions from the app itself and any dependencies that use Spring.

      2) The application creates an ApplicationContext for itself, and a separate ApplicationContext for each dependency that uses Spring.

      3) The application creates an ApplicationContext for itself, and dependencies are responsible for creating their own ApplicationContexts.


      • #4
        Just look into spring and how it is manged here.

        Do NOT create ApplicationsContexts this is like creating processes from inside a DLL/shared lib.