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 :(
The problem is with
You're using
ref
attribute, which references to a bean by itsid
. There is no bean calledorg.sakaiproject.logic.SakaiProxy
, hence the error. You probably want to create a bean calledSakaiProxy
and reference to it, i.e.For more info see this.
EDIT:
sakaiProxy
is aprivate
field. This may cause issues as normally spring injects beans via apublic
setter, i.e.public void setSakaiProxy(SakaiProxy proxy)
unless the field is annotated with@Autowired
(it can handleprivate
fields too). For more info see this, this and this.