Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring newbie, call spring bean methods (2.5, xml) in jsp page, testing
    text
    copied!<p>I'm moving my knowledge to spring and I dont really get how this is working. I'm trying to make a very basic example to make it work, but I couldn't make it work :-(( </p> <p>ApplicationContext.xml</p> <pre><code>&lt;bean id="serviceTest" class="es.mov.jose.agenda.ServiceTest"&gt; &lt;/bean&gt; &lt;bean id="serviceMovility" class="es.mov.jose.agenda.ServiceMovility"&gt; &lt;property name="serviceTest" ref="serviceTest" /&gt; &lt;/bean&gt; &lt;bean name="/jose/req1.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController"&gt; &lt;property name="viewName" value="jose/req1" /&gt; &lt;/bean&gt; </code></pre> <p>ServiceMovility.java</p> <pre><code>package es.mov.jose.agenda; public interface ServiceMovility { public String callTest(); } </code></pre> <p>ServiceMovilityImpl.java</p> <pre><code>package es.mov.jose.agenda; import es.mov.jose.agenda.ServiceMovility; public class ServiceMovilityImpl implements ServiceMovility { private ServiceTest serviceTest; public String callTest() { return serviceTest.getValue(); } } </code></pre> <p>ServiceTest.java</p> <pre><code>package es.mov.jose.agenda; public interface ServiceTest { public String getValue(); } </code></pre> <p>ServiceTestImpl.java</p> <pre><code>package es.mov.jose.agenda; import es.mov.jose.agenda.ServiceTest; public class ServiceTestImpl implements ServiceTest { public String getValue() { return "OK"; } } </code></pre> <p>and finally my req1.jsp </p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;%@ page import="es.mov.jose.agenda.ServiceMovility"%&gt; &lt;%@ page import="es.mov.jose.agenda.ServiceMovilityImpl"%&gt; &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt; &lt;%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn"%&gt; &lt;%@ taglib prefix="sp-forms" uri="http://www.springframework.org/tags/form"%&gt; &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;/head&gt; &lt;body&gt; &lt;jsp:useBean id="serviceMovility" scope="request" class="es.mov.jose.agenda.ServiceMovilityImpl" /&gt; &lt;div class="main" &gt; &lt;% String result = serviceMovility.callTest(); out.println(result); %&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It call serviceMovility perfectly but fail calling serviceTest inside callTest method, it says java.lang.NullPointerException ¿Should I include the bean serviceMovility in that way in jsp file? ¿Why spring doesn't inject serviceTest initialized on serviceMovility?</p> <p>I spent 2 days on this but I failed on all my solutions. I don't know what to do.</p> <p>Thanks in advance. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload