-
May 11th, 2011, 04:00 AM
#1
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.
-
May 11th, 2011, 05:12 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.
-
May 11th, 2011, 06:42 AM
#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>
-
May 11th, 2011, 07:03 AM
#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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules