我有一个服务,它看起来像这样:@PersistenceContext在自动装配Autowired Construcor春季
@Service
public class MyService {
private final EntityManager entityManager;
private final SomeBean someBean;
@Autowired
public DbServiceImpl(EntityManager entityManager, SomeBean someBean) {
this.entityManager = entityManager;
this.someBean = someBean;
}
}
我需要@PersistenceContext
签注EntityManager
。我怎么能这样做,同时保持@Autowired
构造函数? 所以问题是,我可以单独注释构造函数参数entityManager
,同时保留@Autowired
注释?
好的。所以你知道这个解决方法吗? – Neeraj
不幸的是,如果你想使用Spring DI和annotations注入,你唯一的解决方案是在域EntityManager上使用注解@PersistenceContext。 – db80