【问题标题】:No bean named 'org.sakaiproject.logic.SakaiProxy' is defined没有定义名为 'org.sakaiproject.logic.SakaiProxy' 的 bean
【发布时间】:2013-08-19 10:46:49
【问题描述】:

我是 sakai 开发的新手,我选择使用 spring mvc。该工具构建良好,但我得到 No bean named 'org.sakaiproject.logic.SakaiProxy' is defined 错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/index.htm' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Cannot resolve reference to bean 'org.sakaiproject.logic.SakaiProxy' while setting bean property 'sakaiProxy'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.sakaiproject.logic.SakaiProxy' is defined

这是我的springapp-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
<!--<property name="prefix" value="/WEB-INF/jsp/" />-->
    <property name="suffix" value=".jsp" />
    <property name="order" value="10" />
   </bean>

<bean name="/index.htm"
    class="org.sakaiproject.tool.HelloWorldController">
    <property name="sakaiProxy" ref="org.sakaiproject.logic.SakaiProxy"/>
</bean>

这是我的controller

package org.sakaiproject.tool;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.Getter;
import lombok.Setter;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import org.sakaiproject.logic.SakaiProxy;

public class HelloWorldController implements Controller {

/**
 * Hello World Controller
 * 
 * @author Mike Jennings (mike_jennings@unc.edu)
 * 
 */

private SakaiProxy sakaiProxy = null;

public ModelAndView handleRequest(HttpServletRequest arg0,
        HttpServletResponse arg1) throws Exception {

    Map<String, Object> map = new HashMap<String,Object>();
    map.put("currentSiteId", sakaiProxy.getCurrentSiteId());
    map.put("userDisplayName", sakaiProxy.getCurrentUserDisplayName());

    return new ModelAndView("index", map);
}

}

我不知道为什么会出现这个错误,我用谷歌搜索但没有太多帮助:(

【问题讨论】:

  • 我使用 sakai 2.8.2 和 tomcat 5.5

标签: java spring-mvc javabeans sakai


【解决方案1】:

问题出在

<property name="sakaiProxy" ref="org.sakaiproject.logic.SakaiProxy"/>

您正在使用ref 属性,它通过id 引用一个bean。没有名为org.sakaiproject.logic.SakaiProxy 的bean,因此出现错误。您可能想要创建一个名为 SakaiProxy 的 bean 并引用它,即

<bean id="SakaiProxy" class="org.sakaiproject.logic.SakaiProxy" />
...
<property name="sakaiProxy><ref bean="SakaiProxy" /></property>

欲了解更多信息,请参阅this

编辑:

sakaiProxy 是一个 private 字段。这可能会导致问题,因为通常 spring 通过 public 设置器注入 bean,即 public void setSakaiProxy(SakaiProxy proxy) 除非该字段用 @Autowired 注释(它也可以处理 private 字段)。有关详细信息,请参阅thisthisthis

【讨论】:

  • @DinkarThakur 你确定类org.sakaiproject.logic.SakaiProxy 存在于你的构建路径中吗?
  • @DinkarThakur 请查看更新后的答案。如果没有帮助,我将删除整个答案。
猜你喜欢
  • 2012-03-25
  • 2012-05-29
  • 2011-12-08
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多