尝试从 applicationcontext.xml 中提取 bean 时出现 FileNotFound 异常
FileNotFound Exception while trying to extract bean from applicationcontext.xml
This is my project structure image
@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 下。所以你可以只使用文件名
This is my project structure image
@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 下。所以你可以只使用文件名