[Building Sakai] Dependency Injection problem

Artur k Vieira arturkvieira at gmail.com
Mon Aug 31 15:28:11 PDT 2009


Hi, i'am new at web applications development and saka, and i am trying to do
a simple dependency injection in a bean and use it in a servlet.I followed a
lot of tutorials and none worked....there must be some little small thing
that its passing unsen...(sry about my terrible inglish).I am using sakai
2.6, and the servlet api 2.4.I herd that the version specified in the
deployment descriptor could have something to do with it(some say it should
be 2.5), i tried that but it dosent works.

This is the code for the servlet that i registered as a tool in sakai:
http://www.nabble.com/file/p25231272/servlet.jpg 


HelloServiceImpl.java(the bean)

package org.sakaiproject.hello.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.hello.api.HelloService;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;

/**
 * @author wrp
 */
public class HelloServiceImpl implements HelloService {
	private UserDirectoryService userDS;

		/**
	 * (non-Javadoc)
	 * 
	 * @see org.sakaiproject.hello.api.HelloService#hello()
	 */
	public String hello() {
			//User currentUser = this.userDS.getCurrentUser();
		return "Hello Sakai World, Hello: ";// + currentUser.getFirstName() + " "
				//+ currentUser.getLastName();
	
	}

	public void setUserDS(
			UserDirectoryService userDS) {
		this.userDS = userDS;
	}
}




HelloService.java(this is the interface for the bean) 

package org.sakaiproject.hello.api;

public interface HelloService {

        static final String SERVICE_NAME = HelloService.class.getName();
;

        public String hello();
}





web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="HelloApp" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Hello</display-name>
    <description>Hello Sakai Application</description>

	<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/hello-services.xml</param-value>
	</context-param>

    <!-- Sakai request filter -->
    <filter>
        <filter-name>sakai.request</filter-name>
        <filter-class>org.sakaiproject.util.RequestFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>sakai.request</filter-name>
        <servlet-name>sakai.hello</servlet-name><!-- sakai.tasklist era o
valor default -->
        <dispatcher>REQUEST</dispatcher> <!-- mas mudei pois não acho que
fez sentido -->
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>

    <!--  Hello Servlet declaration -->
    <servlet>
        <servlet-name>sakai.hello</servlet-name>
        <servlet-class>org.sakaiproject.tool.hello.HelloTool</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


	<listener>
        <listener-class>org.sakaiproject.util.ToolListener</listener-class>
    </listener>
    
    <!-- tool listener is required -->
    <listener>
       
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>



hello-services.xml(spring configuration file)

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

        <bean id="org.sakaiproject.hello.api.HelloService"
                        class="org.sakaiproject.hello.impl.HelloServiceImpl"
                        singleton="true">
                        <property name="userDS" >
                        <ref
bean="org.sakaiproject.user.api.UserDirectoryService"/>
                        </property>>
        </bean>

</beans>

And the Stack trace in sakai:

http://www.nabble.com/file/p25231272/trace.jpg 

Sry if i puted too much code, its because as i'm a newbie, for me the error
can be anywhere =P
If this is a newbie question, i'm sory guys, i really do, but i am stucked
at 3 days....

Well, thanks very much




-- 
View this message in context: http://www.nabble.com/Dependency-Injection-problem-tp25231272p25231272.html
Sent from the Sakai - Development mailing list archive at Nabble.com.



More information about the sakai-dev mailing list