Results 1 to 4 of 4

Thread: Object creation prob

  1. #1
    Join Date
    May 2011
    Location
    mumbai
    Posts
    37

    Default 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 at 04:05 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2011
    Location
    mumbai
    Posts
    37

    Default

    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>

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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