![](/img/trans.png)
[英]How to import applicationContext.xml and Bean from external jar to @SpringBootTest?
[英]FileNotFound Exception while trying to extract bean from applicationcontext.xml
@Controller
public class LoginController{
@RequestMapping(value = "/registerUser.htm", method = RequestMethod.POST)
public String login(@RequestBody String userProfile){
String message = "Hi Im here";
try{
ApplicationContext context = new ClassPathXmlApplicationContext("/WEB-INF/ApplicationContext.xml");
UserProfile userProfile2= (UserProfile)context.getBean("userProfile") ;
System.out.println(message);
}catch(Exception e){
System.out.println(e.getMessage());
}
return message;
}
}
拋出異常文件未找到。 請幫我解決一下這個。
嘗試刪除前進/
ApplicationContext context = new ClassPathXmlApplicationContext("WEB-INF/ApplicationContext.xml");
您的文件實際上未包含在類路徑中,請嘗試將其放在src / main / ressources下。 所以你只能使用文件名
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.