using Spring JdbcTemplate - injecting datasource vs jdbcTemplate
In the spring-context.xml add the following and
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
and directly you can use jdbcTemplate by autowiring like
@Autowired JdbcTemplate jdbcTemplate;
example:
this.jdbcTemplate.query("select * from ******",new RowMapper());
You can do what you want. The javadoc of JdbcTemplate even clearly says it:
Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference.