我写了一个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。
请帮帮我。 谢谢!
答案 0 :(得分:0)
这些行:
ReadReconciliationFileFactory readFactory=new AllinReadReconciliationFileFactory();
ReadReconciliationFile read=readFactory.produce();
将(可能)创建AllinReadReconciliationFileImpl
,Spring
对此一无所知,因此无法自动装配任何内容。
您需要@Inject
此类的对象,并使用它。