加载时间编织在域对象中不起作用

时间:2013-11-15 11:03:54

标签: java spring aspectj load-time-weaving

我有一个场景,我需要在我的域对象中访问spring managed beans(即使用 new 运算符创建的对象)。我搜索了很多,发现可以使用aspectJ提供的Load Time Weaving来完成。据我所知,我已完成上述所有配置。我是aspectJ的新手。以下是我的代码和配置文件。

域类,

package test.components;

import hibSERVICES.NounHeader.NounHeaderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

@Configurable
public class TestLoadTimeWeaving {

    @Autowired
    private NounHeaderService nounHeaderService;

    public void hello(){
        nounHeaderService.findByPrimaryKey(0L);
    }

}

控制器,

package test.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller
@RequestMapping(value = "/testController.do")
public class TestController{

@RequestMapping(params = "todo=onLoad", method = {RequestMethod.POST, RequestMethod.GET})
public void onLoad(HttpServletRequest request, HttpServletResponse response){
TestLoadTimeWeaving testLoadTimeWeaving = new TestLoadTimeWeaving();
testLoadTimeWeaving.hello();
}
}

的applicationContext.xml

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.directwebremoting.org/schema/spring-dwr
        http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
        http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">



        <context:spring-configured />
        <context:annotation-config />
        <context:component-scan base-package="test" />
        <context:load-time-weaver aspectj-weaving="on"/>
        <bean lass="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect" factory-method="aspectOf"/>

aop.xml文件,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aspectj PUBLIC
    "-//AspectJ//DTD//EN"
    "http://www.aspectj.org/dtd/aspectj_1_5_0.dtd">
<aspectj>
    <weaver>
        <exclude within="*..*CGLIB*" />
    </weaver>
</aspectj>

我写了 -javaagent:c:\ spring-agent-2.5.6.jar作为VM参数

使用以下jar来支持LTW和aspectJ,

  • aspectjrt-1.5.4.jar
  • 弹簧剂2.5.6.jar
  • 弹簧aspect.jar
  • aspectjWeaver-1.5.4.jar
  • 弹簧2.5.6.jar

所有其他spring依赖项工作正常,只有域对象中注入的依赖项(即使用 new 运算符创建的对象)不起作用,即我对这些依赖项变为null。 / p>

请帮助。提前谢谢。

0 个答案:

没有答案