0
我有一个班级TestServiceImpl
,其中有@Service
和@EnabledTransactionManagement
注释。 我指的是其中的2个DAO对象@Autowired Service1DAO s1
和@Autowired Service2DAO s2
。 Service1DAO
和Service2DAO
类标注为@Repository
注释。 这些方法用@Trasanction
标注,并根据需要标注所需参数。春季自动布线为空
问题是: 我能够获得s1
对象,但是当我试图获取s2
对象时,它显示为null。 它们是彼此定义的。
的serivie类是:
@Service
@Scope("prototype")
@EnabledTransactionManagement
public class TestServiceImpl {
@Autowired Service1DAO s1;
@Autowired Service2DAO s2;
@Transation(readOnly = false, propogation = Propagation.REQUIRED_NEW)
public String getXXX1(){
s1.print();
}
@Trsanction(readOnly = false, propogation = Propagation.REQUIRED_NEW)`enter code here`
public String getXXX2(){
s2.write();
}
}
DAO类是:
@Repository
public class Service1DAO implements Service1{
@PersistentContext
EntityManager em;
public String Print(){
em.XXXXXX();
}
}
@Repository
public class Service2DAO implements Service2{
@PersistentContext
EntityManager em;
public String write(){
em.XXXXXX();
}
}
XML包含所提及的部件的扫描pakcage。
服务类中的方法使用@Trasanction进行注释。 – Atul
请添加代码 – reos
何时以及如何访问s2对象?它是由控制器还是您创建一个对象?你能告诉我们你最近怎么样? –