Results 1 to 4 of 4

Thread: Problem of Spring DM + aspectj, can anyone help me?

  1. #1
    Join Date
    Mar 2010
    Posts
    2

    Default Problem of Spring DM + aspectj, can anyone help me?

    Hi guys!
    My osgi-based app structure lists below:
    bundle 1: cn.nfs.demo.biz.common, the interface definition of the business logic;
    bundle 2: cn.nfs.demo.biz.service, the implementation of the bisiness logic;
    bundle 3: WebExtension2, the web tier of the app;
    bundle 4: cn.nfs.demo.springaop, the aspects of the business logci.

    i want to weave the aspect of bundle4 into bundle2, but it fails.

    The aspect definition in bundle 4:
    Code:
    package cn.nfs.demo.springaop;
    
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class HelloAspect {
    	@Pointcut("execution(* cn.nfs.demo.biz.service.UserMgrImpl.printUserName())")
    	public void pointUserName(){}
    	
    	@Around("pointUserName()")
    	public Object performAspect(ProceedingJoinPoint jp) throws Throwable {
    		System.out.println("In aspects!" );
    		return jp.proceed();
    	}
    }
    The aop-beans.xml in the path: /META-INF/spring of bundle 4:
    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"
      default-autowire="byName">
    	
    	<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
    		<property name="proxyTargetClass" value="true"></property>
    	</bean>
    	
    	<bean class="cn.nfs.demo.springaop.HelloAspect" />
    
    </beans>
    The MANIFEST.MF of bundle 4:
    Code:
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Springaop Plug-in
    Bundle-SymbolicName: cn.nfs.demo.springaop
    Bundle-Version: 1.0.0
    Bundle-Activator: cn.nfs.demo.springaop.Activator
    Import-Package: cn.nfs.demo.biz.common,
     org.osgi.framework;version="1.3.0"
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Require-Bundle: com.springsource.org.aspectj.runtime;bundle-version="1.6.5",
     org.springframework.aspects;bundle-version="2.5.6",
     org.springframework;bundle-version="2.5.6"
    Bundle-ClassPath: .

    The biz interface definition in bundle1:

    Code:
    package cn.nfs.demo.biz.common;
    
    import java.util.List;
    
    import cn.nfs.demo.biz.common.entity.UserInfo;
    
    public interface IUserMgr {	
    	void printUserName();
    }
    The biz implementation in bundle 2:
    Code:
    package cn.nfs.demo.biz.service;
    import cn.nfs.demo.biz.common.IUserMgr;
    public class UserMgrImpl implements IUserMgr{
    	@Override
    	public void printUserName() {
    		String msg = "  OiuNt   xOiuNt  ";
    		System.out.println(msg);		
    	}
    }
    Code:
    id	State       Bundle
    0	ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900
    37	ACTIVE      org.eclipse.osgi.services_3.1.200.v20071203
    38	ACTIVE      cn.nfs.demo.mvc_1.0.0
    39	ACTIVE      org.eclipse.equinox.jsp.jasper_1.0.100.v20080427-0830
    40	ACTIVE      org.apache.commons.el_1.0.0.v200806031608
    41	ACTIVE      org.apache.commons.logging_1.0.4.v20080605-1930
    42	ACTIVE      WebExtension1_1.0.0
    43	ACTIVE      com.springsource.javax.servlet.jsp.jstl_1.1.2
    44	ACTIVE      cn.nfs.demo.biz.common_1.0.0
    45	ACTIVE      org.springframework_2.5.6.SEC01
    46	ACTIVE      com.springsource.javax.servlet.jsp_2.1.0
    47	ACTIVE      org.springframework.osgi.extender_1.2.0.rc1
    48	ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006
    49	ACTIVE      org.eclipse.equinox.http.jetty_1.1.0.v20080425
    50	ACTIVE      com.springsource.javax.servlet_2.5.0
    51	ACTIVE      org.springframework.osgi.core_1.2.0.rc1
    53	ACTIVE      WebExtension2_1.0.0
    54	ACTIVE      cn.nfs.demo.mvc.util_1.0.0
    55	ACTIVE      org.eclipse.equinox.jsp.jasper.registry_1.0.0.v20080427-0830
    56	ACTIVE      org.eclipse.equinox.http.registry_1.0.100.v20080427-0830
    57	ACTIVE      com.springsource.org.apache.taglibs.standard_1.1.2
    58	ACTIVE      org.mortbay.jetty_5.1.14.v200806031611
    59	ACTIVE      com.springsource.javax.el_1.0.0
    60	ACTIVE      org.apache.jasper_5.5.17.v200806031609
    61	ACTIVE      org.springframework.web.servlet_2.5.6.SEC01
    62	ACTIVE      org.eclipse.equinox.registry_3.4.0.v20080516-0950
    63	ACTIVE      org.springframework.osgi.web_1.2.0.rc1
    64	ACTIVE      org.springframework.osgi.io_1.2.0.rc1
    65	ACTIVE      org.eclipse.equinox.http.servlet_1.0.100.v20080427-0830
    66	ACTIVE      cn.nfs.demo.biz.service_1.0.0
    67	ACTIVE      org.eclipse.osgi.util_3.1.300.v20080303
    69	ACTIVE      com.springsource.org.aspectj.runtime_1.6.5.RELEASE
    72	ACTIVE      org.springframework.aspects_2.5.6.SEC01
    73	ACTIVE      cn.nfs.demo.springaop_1.0.0


    When i invoke the method UserMgrImpl.printUserName() in web tier, the HelloAspect of bundle 4 does not execute.
    In addition, i implement another aspejct bundle using eclipse aspectj, and it works. However, i think maybe it's hard to incorporate with spring based apps, so i try to use the spring aop form of aspectj.
    Could anyone help me to find out the problem? If the information isn't enough, i will send more information or the whole application.
    Thanks very much!

    OiuNt
    2010-3-22

  2. #2
    Join Date
    Nov 2008
    Location
    Cologne, Germany
    Posts
    12

    Default

    I haven't actually used AspectJ myself, only other technologies that use it, but I'd guess that the annotations don't get picked up by the AspectJAutoproxyCreator. Do you have set any <context:component-scan> in your configuration?
    Also, what environment do you run your application in? I found that component-scan sometimes doesn't work correctly when run from Eclipse. To get this to work, you may try to add the folder containing the compiled classes ('bin' by default, but may also be called 'target/classes', 'build' or such) to the bundles manifest.

    Best regards
    Marcus

  3. #3
    Join Date
    Mar 2010
    Posts
    2

    Default

    Thanks, Marcus!
    i have tried your suggestion, but it doesn't work.


  4. #4
    Join Date
    Mar 2011
    Posts
    2

    Default Osgi with Spring DM and Spring AOP problem

    Hi,

    has anyone tried out load time weaving in an osgi environment using org.eclipse.equinox.weaving.springweaver and not the aspectj weaver? I have managed to make things work with org.eclipse.equinox.weaving.aspectj plugin but not with the springweaver alternative. I need this because I'm using Spring DM and I want to weave, in some bundles, services created by Spring DM. I have read that its possible to do so. Is there any configuration I'm missing at the bundle that needs to be weaved? For the time I only have configured the bundle that contains the aspects with: <context:load-time-weaver weaver-class="org.eclipse.equinox.weaving.springweaver.Eq uinoxAspectsLoadTimeWeaver" /> and I have added a required plugin dependency to this plugin from the one that needs to be weaved.

    Thanks in advance! Any help will be highly appreciated (I've been searching for weeks)

    Olga

Tags for this Thread

Posting Permissions

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