Announcement Announcement Module
Collapse
No announcement yet.
Load applicationContext in web application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load applicationContext in web application

    Hi,

    I am using JSF at front end and spring in the middle. Now i want to load the application context.

    my applicationContext.xml file path is WEB-INF\applicationContext.xml.

    I have made a singleton class to load the application Context but i am unable to get it, how should I? should i use the ClassPathXmlApplicationContext class to load it? if yes then what should be the path?

    right now i have coded this

    Code:
    _applicationContextInstance = new ApplicationContextLoader();
    _springApplicationContextPath = new String [] {"classpath*:/applicationContext.xml"};
    _springApplicationContext = new ClassPathXmlApplicationContext(_springApplicationContextPath);
    and then i tried to load the bean that i defined in applicationContext .. i throws the exception
    Code:
    no such bean is defined
    I am pretty much sure that my bean definition is correct the possible problem is that i am not able to load the applicationContext.xml file.

    Help me out

  • #2
    Maybe this thread might help.

    Regards,
    Andreas

    Comment


    • #3
      Thanks, but this is not helping me out.

      One thing, I have not placed any "context-param" entry in web.xml. Since i am trying to build the app using VWP (Visual Web Pack - NetBeans) and if i add context-param entry with the spring listener entry it gives me deployment error. So I didn't give any entry in web.xml.

      Now, what i want is to load the applicationContext from the path WEB-INF/applicationContext.xml

      Comment


      • #4
        So fix the fact that you have a deployment error, instead of trying to hack your way around it... At least that would be my solution.

        Comment


        • #5
          First of all, to load context from WEB-INF/applicationContext.xml you need not <context-param> entry in the web.xml, <listener> entry would sufffice
          Code:
          <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          context-param you need only to specify non-default location(s) for context and you use default one.

          See
          3.4.4.1. Initial web configuration
          and
          3.8.4. Convenient ApplicationContext instantiation for web applications
          in the Spring reference for details.

          Comment


          • #6
            I have solved the issue.

            I have placed the applicationContext.xml file in classes folder and queried it using this code
            Code:
            _applicationContextInstance = new ApplicationContextLoader();
            _springApplicationContextPath = new String [] {"classpath*:/applicationContext.xml"};
            _springApplicationContext = new ClassPathXmlApplicationContext(_springApplicationContextPath);

            Comment


            • #7
              Originally posted by mdeinum View Post
              So fix the fact that you have a deployment error, instead of trying to hack your way around it... At least that would be my solution.
              I don't know, it's something NetBeans specific issue and i am unable to solve it on my own. I have posted it there but have not got response. Need to get my project working so i am trying to get work around to solve it.

              Comment


              • #8
                Why should it be a Netbeans specific issue? Could be a web.xml/configuration issue. Also when you use the default applicationContext.xml in the WEB-INF directory you don't even need the context-param, you only need the listener.

                Comment


                • #9
                  Originally posted by mdeinum View Post
                  Why should it be a Netbeans specific issue? Could be a web.xml/configuration issue. Also when you use the default applicationContext.xml in the WEB-INF directory you don't even need the context-param, you only need the listener.
                  I don't know whether it's NetBeans specific or web.xml. I have googled around but found no solution. Leme xplain it to you may be you can help me out.

                  If i enter CONTEXT-PARAM entry only and start netbeans it works fine but no sooner i add entry for listener my NetBeans give me error for Deployment Descriptor.

                  Now i had compare the web.xml with some other project which is being developed in Eclipse. But it does not have any issue, that's why i thought may be it's NetBEans specific problem

                  Comment


                  • #10
                    Make sure that your web.xml matches the dtd/xsd. If you have your order of elements wrong Netbeans will give an error. If I had the choice I would post the error here and try to solve that, instead of hacking/working/patching around the framework...

                    Comment


                    • #11
                      yeah, sure i'll dig around tonight.

                      Comment

                      Working...
                      X