我自己找到了一个答案,而不是将其作为配置文件中的资源导入Spring单元测试:
<import resource="classpath*:spring-aspects.xml" />
我必须将其内容直接放在Spring单元测试的配置文件中:
<aop:aspectj-autoproxy/>
<bean class="aspects.PreventNullReturn"
id="preventNullReturn"
></bean>
<aop:config>
<aop:aspect
ref="preventNullReturn"
>
<aop:pointcut
id="preventNull"
expression="execution(* *.getById(..))"
></aop:pointcut>
<aop:before
pointcut-ref="preventNull"
method="replaceNullWithSpecialCase"
></aop:before>
<aop:after
pointcut-ref="preventNull"
method="replaceNullWithSpecialCase"
></aop:after>
</aop:aspect>
</aop:config>
当然,哪一种解决方案比将其放在单独的文件中更糟糕,但这是我使其工作的唯一方法。