Announcement Announcement Module
Collapse
No announcement yet.
Application Context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application Context

    Hi,
    I m new in spring MVC framework, i m facing some problem , in my web project i declared some bean in applicationContext.xml and declare some values in the variables, that is(applicationContext) loaded properly by contextLoaderListener but when i want to use that variables that values is coming null, means values are not set by application context,

    Kindly tell me what i do for that.

    Thanks & Regards,
    R. Soni

  • #2
    Could you please post your applicationContext ? And please, use [code].

    Comment


    • #3
      ApplicationContext

      Code for Applicationcontext

      <bean id="book" class="Book" >
      <property name="a" value="10"></property>
      <property name="b" value="20"></property>

      code from the dispatcher servlet

      <bean name="/home.htm"
      class="HomeController">
      </bean>

      code for controller

      public class HomeController implements Controller{


      Book book;
      public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
      return new ModelAndView("home","message",book.add());

      }
      }

      Comment


      • #4
        Please use [code] as described at http://forum.springframework.org/misc.php?do=bbcode.

        From what I see, you create a "book" bean, and you create a controller. But you dont inject the "book" bean to your controller in your application context.

        Comment


        • #5
          ApplicationContext

          Dear Friend,
          As u know i m new to spring, what i want i m describing below.
          1. I have a training-servlet.xml, inside that i put the whole code as u see, now if i set the parameter in the training-servlet.xml, it is working fine, means if i declare book object in the /homecontoller then i got the value.

          2. But in my project all the beans are declared in the applicationContext and in that file all the parameter are set,

          3. Now my problem is that as u suggest that bean is not injecting and i visit that link as u provided. but i could not gotted. can u add some code in my homecontroller by which i m able to get the book parameter values which was set in the applicationcontext.

          Waiting ur response.

          R.Soni

          Comment


          • #6
            The link I gave you is to format the code you post on the forum to make it more readable. Just like I did below :

            Code:
            <bean name="/home.htm" class="HomeController">
              <property name="book" ref="book"/>
            </bean>
            You should add a setter for book on your controller, and that should be it.

            Comment

            Working...
            X