I’m trying to replace my CDI/EJB annotations with Spring ones. But I’m struggeling how to do it right.
This is what I have in CDI/EJB:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
class Service {
@Inject
EntityManager em;
}
@Named
@RequestScoped
class Facade {
@Inject
Service service;
}
Now I would do the following:
@Stateless
@Transactional
@Repository
class Service {
@Inject
EntityManager em;
}
What about the stateless? What is the aquivalent in spring?
Obvious I cannot just remove this annotation, bc then I’m getting these exception:
javax.el.PropertyNotFoundException: /input.xhtml @15,30 registerButtonAction="#{facade.createNew()}": The class 'Facade$Proxy$_$$_WeldClientProxy' does not have the property ...
Further:
@Named
@Service
class Facade {
@Autowired
Service service;
}
Do I have to simply replace all @Inject annotations with @Autowired?
Is there something in Spring that takes care of EL naming, so that I can remove the @Named?
Do I have to annotate my JPA entities too?
StatelessandStatefulBeans areEJBconcepts, butSpringoffers similar services through Service Beans. Put the@Serviceannotation in your Business Logic classes, and if you want your beans to be “Stateless” or “Stateful” just configure your bean scope (likeRequestorSession).Springalso has a built-in transaction management API, so your Transaction annotations may need to be changed.Finally,
Springis compatible with many persistence frameworks includingJPA. IF you want to keepJPAit is OK, and feel free to change it for another technology if you desire (maybeHibernate, orMyBatis)