I've got a class that looks something like this:
AbstractTransaction class looks like this:
public class ChangeQuantityTransaction extends AbstractTransaction
public Object doTransaction(MapSqlParameterSource params) throws Exception
a few sql updates are performed in here
public abstract class AbstractTransaction
protected JdbcTemplate _jt;
public Object doTransaction(MapSqlParameterSource params) throws Exception;
protected void setDataSource(DataSource dataSource)
_jt = new JdbcTemplate(dataSource);
I am working with a legacy servlet and get a changeQuantityTransaction in the servlet's init method:
<bean id="changeQuantityTransaction" class="mypackage.ChangeQuantityTransaction" />
<ref bean="changeQuantityTrans" />
private ChangeQuantityTransaction _trans;
public void init(ServletConfig config)
Object obj = config.getServletContext().getAttribute("changeQuantityTrans");
private void setTransaction(ChangeQuantityTransaction trans)
_trans = trans;
Here is the confusing part. When I annotate ChangeQuantityTransaction with @Configurable, the method setDataSource (in the abstract parent) is called only once. If I annotate the class with @Component, setDataSource is called twice.
Why do the different annotations cause setDataSource to be called a different number of times? Looking at the Spring debug output I can see the bean is created as a singleton, but I don't see why it is being initialized twice, and I can't find anything in the reference material that tells me why @Configurable and @Component would behave in a different manner.
Another question - which annotation is better here, @Configurable or @Component?