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

  • Object creation prob

    Dear all,

    when i deploy the application container is reading the context.xml and datasource object is set in my application.But while running am getting null datasource.

    private DataSource dataSource = null;

    /**
    * Retourne la datasource.
    * @return la datasource.
    */
    public DataSource getDataSource() {
    return dataSource;
    }

    /**
    * Set la datasource.
    * @param dataSource la datasource.
    */
    public void setDataSource(final DataSource dataSource) {
    System.out.println("in datasource");
    this.dataSource = dataSource;
    System.out.println("in datasource1");
    this.npjt = new NamedParameterJdbcTemplate(dataSource);
    System.out.println("in datasource2");
    System.out.println("in datasource3"+this.npjt);
    }

    but here i am getting null as object

    DataSource dataSource= getDataSource() ;
    dataSource here am getting nulll while running plz help
    npjt.queryForObject(sql, paramSource, rowMapper);
    Last edited by junugari; May 11th, 2011, 05:05 AM.

  • #2
    Please use [ code][/code ] tags when posting code that way it remains readable ...

    If it is injected it is there, if you don't see it you operate on a different instance of your object then the one that gets the bean injected. Make sure you use the configured bean from the applicationcontext and not a new instance.

    Comment


    • #3
      Dear Marten,

      I am getting datasource while loading.But same thing am not getting while running the application.

      here am pasting my code

      Bean:
      private DataSource dataSource = null;

      public DataSource getDataSource()
      {
      return dataSource;
      }

      public void setDataSource(final DataSource dataSource)
      {
      this.dataSource = dataSource;
      this.npjt = new NamedParameterJdbcTemplate(dataSource);
      }

      While running the code I am getting null as datasource here

      public Object queryForObject(final String sql, final SqlParameterSource paramSource, final RowMapper rowMapper) {

      return npjt.queryForObject(sql, paramSource, rowMapper);

      }

      context.xml

      <bean id="commonJdbcTemplate" class="com.carrefour.fr.portail.carburant.CommonJd bcTemplate">
      <property name="dataSource" ref="portailCarburantDataSource"></property>
      </bean>

      Comment


      • #4
        Again use [ code][/code ] tags when posting code !!!

        As stated make sure you use the instance configured in the applicationcontext and not a new instance... The code snippet you show nowhere uses the datasource, next to that post the stacktrace (again remember the [ code][/code ] tags !!!!). And post the code that is using that queryForObject method...

        Comment

        Working...
        X