无法在Web应用程序中加载spring bean

时间:2016-07-09 06:54:45

标签: spring jsp spring-mvc servlets

我在我的Web应用程序中有一个帮助器类,它负责调用spring bean上的方法。

以下是课程定义:

package org.learning.spring.remoting;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ClientInvoker {
    public static int sum(int a, int b) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:client-beans.xml");
        Calculation calculation = (Calculation)  context.getBean("calculationBean");
        return calculation.add(a, b);
    }
}

在我的jsp中,下面是调用ClienInvoker

上的函数的代码
<%@page import="org.learning.spring.remoting.ClientInvoker"%>  

<%  
  int a=Integer.parseInt(request.getParameter("number"));  
  int b=Integer.parseInt(request.getParameter("number"));  
  out.print("cube of "+ClientInvoker.sum(a, b));  
%>

当我运行Web应用程序时,我得到以下异常:

org.apache.jasper.JasperException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [client-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [client-beans.xml] cannot be opened because it does not exist
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

基本上,它没有加载我放在WEB-INF目录下的client-beans.xml文件。

有人能让我知道我哪里出错了。

0 个答案:

没有答案