我试图在春天使用基于声明的AOP运行JUnit测试用例.当我运行测试时,我得到ClassNotFound Exception(已清除),还有一个例外java.lang.IllegalStateException:无法加载ApplicationContext.异常似乎很简单,但我无法解决它.
它是一个Junit测试用例,所以不需要main方法,因为我没有运行客户端代码,测试用例没有运行.如果我错了,请告诉我.
有人可以帮我解决这个错误,我试图重建,清理构建项目,删除并重新添加所有可执行jar文件.
这是代码
package declarativeBeans.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import declarativeBeans.Performer1;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext_declarative_based_AOP.xml")
public class AspectTest1 {
@Autowired
ApplicationContext context;
@Test
public void audienceShouldApplaud() throws Exception{
Performer1 eddie = (Performer1) context.getBean("eddie");
eddie.perform1();
}
}
Run Code Online (Sandbox Code Playgroud)
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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- Target class -->
<bean id="target" class="declarativeBeans.InstrumentList1">
<property name="instr">
<bean class="declarativeBeans.Guitar1" />
</property>
</bean>
<!-- Advice/Advisor -->
<bean id="Audience" class="declarativeBeans.Audience1" /> …Run Code Online (Sandbox Code Playgroud)