ApplicationContext. xml files are stored in different locations, resulting in different paths in jUnit testing. applicationcontext
If the applicationContext. xml file is placed under src, the path written during jUint testing should be as follows:
@ Testpublic void testFindByPage () {ApplicationContext ctx = new ClassPathXmlApplicationContext ("applicationContext. xml"); AccountDao dao = ctx. getBean (AccountDao. class );
But if the applicationContext. xml file is placed under the WEB-INF, the path written during the jUnit test will be different.
If this is not the case, the applicationContext. xml file cannot be found during the test.
Private String conf = "WebRoot/WEB-INF/applicationContext. xml "; @ Testpublic void savetest () {ApplicationContext ac = new FileSystemXmlApplicationContext (conf); AllDao ad = ac. getBean (AllDao. class); User u = new User (); u. setUsername ("admin001"); u. setPassword ("123456"); ad. register (u );}