Can I use the Dependency Injection in this case ? How can I configure the bean Article in the applicationContext.xml?
public class Test{
public void methodX(){
.....
while{
Article a=new Article();
...
}//while
}//methodX
}//Test
Edit:
This is the solution which I have used:
package factory;
import bean.ArticoliOrdine;
public abstract class ArticlesFactory {
public abstract Article createArticle();
}
@Transational
public class CartDAOImpl implements CartDAO {
@Autowired
private Cart cart;
@PersistenceContext
private EntityManager em;
@Autowired
ArticlesFactory articlesFactory;
public void buy(){
....
while{
Article article=articlesFactory.createArticle();
.....
em.persist(article);
}//while
}//buy
}//CartDAOImpl
In applicationContext
<bean id="articolesFactory" class="factory.ArticlesFactory">
<lookup-method name="createArticles" bean="articles"/>
</bean>
<bean class="bean.Articles" id="articles" scope="prototype"/>