Results 1 to 6 of 6

Thread: AspectJ or AOP and Spring DM

  1. #1
    Join Date
    Jan 2010
    Posts
    12

    Default AspectJ or AOP and Spring DM

    Hi guys,

    currently I'm programming a small test application with Spring-DM and Equinox to learn Spring and Spring-DM. Now I would like to integrate some kind of dynamic AOP/AspectJ behaviour to it. E. g. I would like to have a separate bundle containing all aspects. These aspects should be used for bundles (logic bundles, not the aspect bundle) which are already deployed as well as for bundles I might deploy in the future (when I deploy a new bundle the aspects should automatically work on these bundles without any manual work). Moreover when the (existing) aspects develop over time (aspects added, modified, removed) I want to be able to replace the aspect bundle with a newer version of it and the new version should then be used for all existing bundles (without any manual work).

    Currently I'm using compile-time weaving with AspectJ but with this apporach I have to recompile all bundles when I modify the existing aspects. Moreover all bundles need to have some reference to the project containing the aspects. I would like to change this to have my bundles be dependend on a single aspect bundle (via package dependency if possible), which I can replace when I have to modify the existing aspects.

    Is this possible with load-time weaving? Can anyone of you give me some hints how to achieve this and where I can find more information or sample code? I'm not bound to AspectJ and Equinox in case this is easier to achieve with Spring AOP and/or dm-server. But as I said before I'm not experienced with Spring AOP, Spring-DM and OSGI yet so it's hard to get this up and running.

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2010
    Posts
    12

    Default

    I found some posts here and on the internet regarding Equinox Aspects as a possible solution for this. But the project looks a little bit inactive and the last post of the contributor here in the forum regarding this topic has been some month ago so I'm wondering if this is still the way to go. Moreover I would appreciate if someone can tell me if this solution is stable or if there are some issues with this approach. Anyway I will give it a try.

    Still any help is appreciated.

    Have a nice weekend guys
    Last edited by fkh; Feb 12th, 2010 at 03:59 PM.

  3. #3
    Join Date
    Jan 2010
    Posts
    12

    Default

    Hi guys,

    I managed to get everything up and running so no need for help anymore.

    fkh

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Hi fkh,

    It would help others if you could also post the solution to your problem. As for learning Spring and Spring DM, I would recommend first sticking with Spring and once you're comfortable with it (including AOP and AspectJ) consider moving to Spring DM/OSGi.
    The modularity introduced by OSGi can cause a number of problems which complicates things for users non-familiar with Spring and AOP.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Jan 2010
    Posts
    12

    Default

    Quote Originally Posted by Costin Leau View Post
    Hi fkh,

    It would help others if you could also post the solution to your problem. As for learning Spring and Spring DM, I would recommend first sticking with Spring and once you're comfortable with it (including AOP and AspectJ) consider moving to Spring DM/OSGi.
    The modularity introduced by OSGi can cause a number of problems which complicates things for users non-familiar with Spring and AOP.
    Hi Costin,

    thx for your advice. I got myself a couple of Spring and OSGi related books to start with and up to now everything works pretty good.

    Back to my initial post - I just followed the quick start tutorial on the Equinox Aspects website (with some minor modifications on how I launched the Equinox container) and I was able to use AspectJ aspects in a dynamic way. I didn't try to use Aspects in Spring because for the moment it's fine with me as it is. As soon as I will try this combination (Spring AOP + Equinox Aspects) I will post my results in this thread.

    I still can't find any information on how stable this solution is (except a blog entry that it may be used in the upcoming Eclipse 3.6 release). Is someone of you using Equinox Aspects in a productive environment and can share some experience please?

    fkh

  6. #6
    Join Date
    Feb 2010
    Posts
    6

    Default An AOP Sample of Equinox_Weaving + Spring DM

    This sample can mix AOP / IoC / OSGi together.

    So, as shorter as possible.
    The startup.bat is as:
    Code:
    java -Dosgi.compatibility.bootdelegation=true -cp org.eclipse.osgi_3.6.0.v20100128-1430.jar;org.eclipse.equinox.weaving.hook_1.0.0.v20100108.jar org.eclipse.core.runtime.adaptor.EclipseStarter -configuration configuration -console
    the environment compounded of several bundles, for detail see configuration\config.ini:
    Code:
    osgi.bundles= \
     org.eclipse.equinox.common_3.6.0.v20100125.jar@start, \
     org.eclipse.osgi.services_3.2.100.v20100108.jar@start, \
     org.eclipse.aspectj_2.0.2.e35x-20100105-0900.jar, \
     org.eclipse.equinox.weaving.aspectj_1.0.0.v20100108.jar, \
     org.aspectj.runtime_1.6.7.20100105084524, \
     org.aspectj.weaver_1.6.7.20100105084524, \
     spring-osgi-core-1.2.1.jar@start, \
     spring-osgi-extender-1.2.1.jar@start, \
     spring-osgi-io-1.2.1.jar@start, \
     com.springsource.org.aopalliance-1.0.0.jar@start, \
     org.springframework.aop-2.5.6.SEC01.jar@start, \
     org.springframework.beans-2.5.6.SEC01.jar@start, \
     org.springframework.context-2.5.6.SEC01.jar@start, \
     org.springframework.core-2.5.6.SEC01.jar@start, \
     com.springsource.slf4j.api-1.5.10.jar@start, \
     com.springsource.slf4j.log4j-1.5.10.jar, \
     com.springsource.slf4j.org.apache.commons.logging-1.5.0.jar@start, \
     log4j.osgi-1.2.15-SNAPSHOT.jar@start, \
     org.springframework.osgi.log4j.config, \
     osgi.demo.api_1.0.0.jar, \
     osgi.demo.impl_1.0.0.jar, \
     osgi.demo.impl.log_1.0.0.jar, \
     osgi.demo.oper_1.0.0.jar
    
    # org.eclipse.equinox.weaving.caching_1.0.0.200808061839.jar@start, \
    # org.eclipse.equinox.weaving.caching.j9_1.0.0.200808061839.jar@start, \
    
    eclipse.ignoreApp=true
    
    osgi.bundles.defaultStartLevel=5
    osgi.framework=org.eclipse.osgi
    osgi.configuration.cascaded=false
    
    org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
    
    # Equinox Aspects
    osgi.framework=org.eclipse.osgi_3.6.0.v20100128-1430.jar
    osgi.framework.extensions=org.eclipse.equinox.weaving.hook
    
    aj.weaving.verbose=true
    org.aspectj.weaver.showWeaveInfo=true
    org.aspectj.osgi.verbose=true
    the last 4 bundles is for testing the environment.
    **.impl.log_1.0.0.jar bundle used aop for logging the action of **.impl_1.0.0.jar

    **.impl_1.0.0.jar used IoC for implementation of **.api_1.0.0.jar

    and **.oper_1.0.0.jar simulated the invoker of **.impl_1.0.0.jar services
    **.api_1.0.0.jar is just an interface bundle.

    **.impl has spring folder under META-INF, contains 2 file:
    orderservice.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
      <bean name="orderService" class="osgi.demo.impl.OrderServiceImpl" init-method="start" destroy-method="stop"/>
    
    </beans>
    orderservice-osgi.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:osgi="http://www.springframework.org/schema/osgi"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
                          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
    
      <osgi:service id="orderOSGiService" ref="orderService"
        interface="osgi.demo.api.OrderApi">
      </osgi:service>
    
    </beans>
    **.oper has folder spring under META-INF contains:

    orderclient.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
      <bean name="orderClient" class="osgi.demo.oper.OrderClient"
            init-method="start" destroy-method="stop">
            <property name="orderService" ref="orderService"/>
      </bean>
    
    </beans>
    orderclient-osgi.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:osgi="http://www.springframework.org/schema/osgi"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
                          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
    
        <osgi:reference id="orderService" interface="osgi.demo.api.OrderApi"/>
    
    </beans>
    MANIFEST.MF of **.log is:
    Code:
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Logging Aspect of lic.impl
    Bundle-SymbolicName: osgi.demo.impl.log
    Bundle-Version: 1.0.0
    Bundle-Vendor: Regular Individual
    Require-Bundle: org.aspectj.runtime;bundle-version="1.6.1";visibility:=reexport
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Import-Package: org.apache.commons.logging;version="1.1.1",
     org.osgi.framework;version="1.4.0"
    Export-Package: osgi.demo.impl.log
    Eclipse-SupplementBundle: osgi.demo.impl
    and aop.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <aspectj>
        <aspects>
            <aspect
                name="osgi.demo.impl.log.OrderServiceImpl" />
        </aspects>
    </aspectj>
    at last, the **.log4j.config has a log4j.properties in META-INF folder and with MANIFEST.MF:
    Code:
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Log4J Configuration
    Bundle-SymbolicName: org.springframework.osgi.log4j.config
    Bundle-Version: 1.0.0
    Fragment-Host: org.springframework.osgi.log4j.osgi;bundle-version="1.2.15"
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    OK, that's all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •