2

ドメイン オブジェクト (つまり、新しい演算子で作成されたオブジェクト) でSpring Managed Bean にアクセスする必要があるシナリオがあります。いろいろ調べたところ、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);
    }

}

コントローラ、

パッケージ 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をサポートし、

  • spectjrt-1.5.4.jar
  • spring-agent-2.5.6.jar
  • 春のアスペクト.jar
  • アスペクトjWeaver-1.5.4.jar
  • 春-2.5.6.jar

他のすべての春の依存関係は正常に機能していますが、ドメイン オブジェクト (つまり、新しい演算子で作成されたオブジェクト) に注入された依存関係のみが機能していません。つまり、これらの依存関係に対して null を取得しています。

親切に助けてください。前もって感謝します。

4

0 に答える 0