Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:44:29+00:00 2026-06-11T07:44:29+00:00

I’m moving my knowledge to spring and I dont really get how this is

  • 0

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 :-((

ApplicationContext.xml

<bean id="serviceTest" class="es.mov.jose.agenda.ServiceTest">
</bean>

    <bean id="serviceMovility" class="es.mov.jose.agenda.ServiceMovility">
    <property name="serviceTest" ref="serviceTest" />
</bean>

    <bean name="/jose/req1.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
    <property name="viewName" value="jose/req1" />
</bean>

ServiceMovility.java

package es.mov.jose.agenda;

public interface ServiceMovility {
        public String callTest();
}

ServiceMovilityImpl.java

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

}  

ServiceTest.java

package es.mov.jose.agenda;

public interface ServiceTest {
        public String getValue();
}    

ServiceTestImpl.java

package es.mov.jose.agenda;

import es.mov.jose.agenda.ServiceTest;

public class ServiceTestImpl implements ServiceTest {

    public String getValue() {
        return "OK";
    }

}

and finally my req1.jsp

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="es.mov.jose.agenda.ServiceMovility"%>
<%@ page import="es.mov.jose.agenda.ServiceMovilityImpl"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sp-forms" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">    
</head>
<body>
<jsp:useBean id="serviceMovility" scope="request"     class="es.mov.jose.agenda.ServiceMovilityImpl" />
<div class="main" >
    <%
    String result = serviceMovility.callTest();
    out.println(result);
    %>
</div>
</body>
</html>

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?

I spent 2 days on this but I failed on all my solutions. I don’t know what to do.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:44:31+00:00Added an answer on June 11, 2026 at 7:44 am

    Use implementations instead of interfaces while defining beans:

    <bean id="serviceTest" class="es.mov.jose.agenda.ServiceTestImpl" />
    
    <bean id="serviceMovility" class="es.mov.jose.agenda.ServiceMovilityImpl">
      <property name="serviceTest" ref="serviceTest" />
    </bean>
    
    <bean name="/jose/req1.do"
        class="es.mov.jose.agenda.Req1Controller">
      <property name="viewName" value="jose/req1" />
      <property name="serviceMovility" ref="serviceMovility" />
    </bean>
    

    plus, in your *Impl classes define setters to injected dependencies, i.e. in ServiceMovilityImpl:

    public void setServiceTest(ServiceTest serviceTest) {
      this.serviceTest = serviceTest;
    }
    

    EDIT:

    You’re doing it wrong… Don’t inject beans into JSP (via jsp:useBean), but directly to Controller. Define your own controller:

    package es.mov.jose.agenda;
    
    final class Req1Controller extends ParameterizableViewController {
    
      private ServiceMovility serviceMovility;
    
      @Override
      protected ModelAndView handleRequestInternal(HttpServletRequest request,
          HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView(getViewName());
        mav.addObject("callTest", serviceMovility.callTest());
        return mav;
      }
    
      public void setServiceMovility(ServiceMovility serviceMovility) {
        this.serviceMovility = serviceMovility;
      }
    }
    

    Edit your ApplicationContext.xml as I did above (use Req1Controller instead ParameterizableViewController), and in JSP you’ll have ${callTest} variable:

    <body>
      <div class="main" >
        <c:out value="${callTest}" />
      </div>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.