Announcement Announcement Module
No announcement yet.
Spring Integration w/ DM Server where "new ClassPathXmlApplicationContext()" not work Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration w/ DM Server where "new ClassPathXmlApplicationContext()" not work


    our standalone application uses Spring Integration.
    It listens to a directory in interval.
    New files are read and a bean will create some entities in a database rest upon the content of these files.

    There is a main application, where the system is started.

    public class App {
        static AbstractApplicationContext context;
        public static void main(String[] args) {
            context = new ClassPathXmlApplicationContext("beans.xml");
        public static AbstractApplicationContext getContext() {
            return context;

    Now with OSGI, in the Spring DM Server, the Web bundle should start the work in the Integration bundle.
    First try was: the web bundle calls a method in the integration bundle, wich creates the new context like in the upper code.

    But this won't work.
    I need something like the following.
    The web bundle uses a gateway to the integration bundle.
    Via this gateway the integration work should be started.
    Here is a good example how to use Spring Integration in OSGI with gateways:
    The inbound uses a gateway to the outbound wich offers a file:outbound-gateway to write files containing messages send by the inbound.

    Here is the XML configuration file in the META-INF/spring folder which is similar to the configuration in the Spring Integration standalone application:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="" xmlns:xsi=""
        xmlns:context="" xmlns:p=""
        xmlns:integration="" xmlns:file=""
        <!-- process property placeholders using a property file -->
        <context:property-placeholder location="META-INF/spring/" />
        <file:inbound-channel-adapter directory="file:${}" auto-startup="true"
            filename-pattern="${incoming.pattern}" id="incoming" channel="files" />
        <integration:channel id="files" datatype="">
            <integration:queue capacity="10" />
        <!-- Gateway which creates new jobs in the database -->
        <bean id="registerJob" class="" />
        <!-- Call the specified bean with message payloads of the input channel -->
        <integration:service-activator input-channel="files" ref="registerJob" method="register" />
        <!-- -->
        <integration:poller id="poller" default="true" max-messages-per-poll="3">
            <integration:interval-trigger interval="2000" />
        <!--  -->
        <osgi:reference id="hibernateSampleDAOImpl" interface="" />
    Is the application context created automativally by DM Server?
    This code snippet --auto-startup="true"-- has no effect.

    So, how to solve this?

    King regards

  • #2

    I would suggest to read up Spring-DM documentation especially the chapter about ApplicationContext creation:
    OSGi introduces a radically different programming, class-loading and deployment model (remember no more class-path in a normal sense), which means a lot of things needs to be done differently to accommodate this model, that is why we have Spring-DM as a foundation block for dmServer. It uses its own custom implementation of ApplicationContext interface (OsgiBundleXmlApplicationContext). However, before you venture into creating your own Application Context:
    • Yes, ApplicationContext is created automatically by Spring-DM Extender bundle.
    • Bundles communicate with one another via OSGi services (as in the example you were mentioning in your post), to accommodate OSGi Service dynamics
    So, all you need is two bundles: web and integration.
    Integration bundle would export its Gateway as an OSGi service (<osgi:service/>). Such Gateway service would be imported by the web bundle (<osgi:reference/>).
    Again, the example from our blogs that you were referring to clearly shows how to accomplish that as it demonstrates two integration bundles communication with one another via OSGi services.


    • #3
      Thanks for Your fast reply.
      I will read the documentation again and will try your proposal.