Skip to content

Instantly share code, notes, and snippets.

@rponte rponte/
Last active Dec 14, 2019

What would you like to do?
Injecting @Autowired dependencies into self-instantiated objects with Spring
public class Cliente {
@Autowired // that's important!
private transient ClienteRepository repository;
// atributos da entidade
public List<Orcamento> orcamentosAPartirDeDeterminadoAno(int ano){
return this.repository.buscaOrcamentosAPartirDoAno(this, ano);
public class RepositoryAwareListener {
public void postLoad(Object entity) throws Exception {
.getAutowireCapableBeanFactory().autowireBean(entity); // injects all dependencies
// another fancy solution would be using AspectJ Weaver with @Configurable annotation
You can’t perform that action at this time.