自动注射失败

时间:2017-02-20 08:24:58

标签: spring junit mybatis

我写了一个TEST课。

@ActiveProfiles("dev")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {     "classpath:spring/appContext.xml","classpath:spring/appContext-datasource.xml"})
@Transactional
public class ReadReconciliationFileTest {
@Autowired
private OriginalReconciliationInformationExtMapper originalReconciliationInformationExtMapper;
@Autowired
private ProblematicReconciliationInformationMapper problematicReconciliationInformationMapper;
@Test
public void insertReconciliationInformation(){
    ReadReconciliationFileFactory readFactory=new AllinReadReconciliationFileFactory();
    ReadReconciliationFile read=readFactory.produce();
    List<ReconciliationBean> list=read.readFile("/Users/wuchangming/Documents/work/通联/tlt_javademo/PDS2006040000004450420170216.txt");
    for(int i=0;list!=null&&i<list.size();i++){
        originalReconciliationInformationExtMapper.insertInformation(list.get(i));
    }
    List<ReconciliationBean> list2=originalReconciliationInformationExtMapper.getInformationList(null);
    List<String> list3=problematicReconciliationInformationMapper.getProblematicDataList("9",null);
    Assert.assertEquals(list.size(),list2.size()+list3.size());
}
}

在此课程中,Autowired有效。 但是在ReadReconciliationFile类AllinReadReconciliationFileImpl的实现中,Autowired injection为null。 enter image description here

请帮帮我。 谢谢!

1 个答案:

答案 0 :(得分:0)

这些行:

ReadReconciliationFileFactory readFactory=new AllinReadReconciliationFileFactory();
ReadReconciliationFile read=readFactory.produce();

将(可能)创建AllinReadReconciliationFileImplSpring对此一无所知,因此无法自动装配任何内容。

您需要@Inject此类的对象,并使用它。