错误代码:
No bean named 'attachementService' is defined
用的是同一个配置文件,为何两处地方运行却截然不同?
错误代码:
No bean named 'attachementService' is defined
用的是同一个配置文件,为何两处地方运行却截然不同?
给你贴下我的代码吧
通用父类
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext-resources.xml"})
public class BaseJunit4Test {
}
调用业务类:
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import com.hshbic.selfservice.hardware.service.BaseJunit4Test;
import com.hshbic.selfservice.hardware.service.DeviceTemplateService;
public class DeviceTemplateServiceTest extends BaseJunit4Test{
@Autowired
private DeviceTemplateService deviceTemplateService;
@Test
@Transactional //标明此方法需使用事务
@Rollback(true) //标明使用完此方法后事务不回滚,true时为回滚
public void testUseTemplate(){
deviceTemplateService.addDeviceTemplate(null);
}
}