Announcement Announcement Module
No announcement yet.
Use app context from Spring Integration app Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use app context from Spring Integration app

    In my app I have some processes done in Spring Integration and some in Spring Batch jobs. I am running the batch jobs from the command line. However, I would like to use the Application Context loaded by the Spring Integration application. Many of my jobs reuse the same service and data source. How can I reuse the application context already loaded. I assume I need to create Java class I can call from the command line and create a job launcher. I'm not clear on how I would get the existing context though. Below is how load the context for the Spring Integration app.

    private static AbstractApplicationContext context;
    public static void main(String[] args) {
    		context = new ClassPathXmlApplicationContext("appContext.xml");


  • #2
    Does this work for you?

    public class ApplicationContextManager {
        private static ApplicationContextManager instance;
        private static ApplicationContext ctx;
        static {
            ctx = new ClassPathXmlApplicationContext("appContext.xml");
            instance = new ApplicationContextManager();
         public static ApplicationContextManager getInstance() {
             return instance;
         public ApplicationContext getAppContext() {
             return ctx;

    Then, where ever you wish to access the same context (i.e.from your SpringBatch app), you just get an instance of that class in order to access it's ApplicationContext:

    ApplicationContext ctx = ApplicationContextManager.getInstance().getAppContext();