Is it possible to inject beans to a JPA @Entity
using Spring\'s dependency injection?
I attempted to @Autowire ServletContext but, while the server did
After a long time I stumbled across this SO answer that made me think of an elegant solution:
@Autowired private AutowireCapableBeanFactory autowirer;
String beanName = fetchedEntity.getClass().getSimpleName();
autowirer.autowireBean(fetchedEntity);
fetchedEntity = (FetchedEntity) autowirer.initializeBean(fetchedEntity, beanName);
Your entity will then be able to access the autowired fields as any @Component can.