Announcement Announcement Module
No announcement yet.
noob applicationContext problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • noob applicationContext problem


    Ok, I am just trying to access properties of a particular bean in my applicationContext.xml file.

    <bean name="tbc" class="springapp.web.TestJDBC">
    <property name="ts" value="works"/>

    The applicationContext.xml file is located at /WEB-INF/applicationContext.xml. I've tried several techinques that I have seen online, here is my latest attempt:

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("/WEB-INF/applicationContext.xml");
    TestJDBC j = (TestJDBC) context.getBean("tbc");;

    Here is the code for the TestJDBC class.

    public class TestJDBC implements ApplicationContextAware{

    //private DataSource myds;
    private String ts;

    public void setTs(String ts){
    this.ts = ts;

    public void gr(){

    System.out.println("variable = "+ts);
    //return ds.queryForInt("select count(*) from EMP");

    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
    //throw new UnsupportedOperationException("Not supported yet.");


    I get a null pointer exception as the app can't see the application context file.

    Any thoughts?

  • #2
    You shouldn't manually create application context in case of web-application usage. It should be configured to be created automatically on web-application startup. Feel free to get more details on that at Spring MVC tutorial - 1.6. Modify 'web.xml' in the 'WEB-INF' directory.

    Also I'd suggest you to use simple standalone applications (not web applications) for studying spring.


    • #3
      It should be configured to be created automatically on web-application startup.

      Nouveau taux a pret 0 conditions 2010 | Le eco pret a taux 0 credit zero travaux | Nouveau pret a taux 0