No bean named 'org.sakaiproject.logic.SakaiProxy' is defined

680 Views Asked by At

I'm new to sakai development and i choose to use spring mvc. the tool is building fine but i'm getting No bean named 'org.sakaiproject.logic.SakaiProxy' is defined error

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

This is my 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>

and this is my 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 ([email protected])
 * 
 */

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);
}

}

i don't know why this error is coming i google it out but not much help :(

1

There are 1 best solutions below

2
On

The problem is with

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

You're using ref attribute, which references to a bean by its id. There is no bean called org.sakaiproject.logic.SakaiProxy, hence the error. You probably want to create a bean called SakaiProxy and reference to it, i.e.

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

For more info see this.

EDIT:

sakaiProxy is a private field. This may cause issues as normally spring injects beans via a public setter, i.e. public void setSakaiProxy(SakaiProxy proxy) unless the field is annotated with @Autowired (it can handle private fields too). For more info see this, this and this.