Results 1 to 6 of 6

Thread: Application Context

  1. #1
    Join Date
    Jan 2008
    Posts
    6

    Default 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. #2
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

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

  3. #3
    Join Date
    Jan 2008
    Posts
    6

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

    }
    }

  4. #4
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    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.

  5. #5
    Join Date
    Jan 2008
    Posts
    6

    Default 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

  6. #6
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •