簡體   English   中英

嘗試從applicationcontext.xml提取bean時發生FileNotFound異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM