The @EJB
is used to inject an EJB into another EJB, in the JEE world.
See: Should I use @EJB or @Inject
In Spring the equivalent injection is done by the use of @Autowired
.
Example:
@Service
public class MyServiceImpl implements MyService {
}
@Controller
public class MyController{
@Autowired MyService myService;
}
@Service
is a Spring annotation for annotating a class at a service layer.
Other annotations: @Component
, @Repository
, @Controller
, @Service
.
See: What's the difference between @Component, @Repository & @Service annotations in Spring?
I would say:
@Component
, @Repository
, @Controller
& @Service
are closer to @Stateless
or @Statefull
, and
@EJB
is similar to @Autowired
UPDATE
@Autowired
tells Spring framework to find dependecies for you. The @Inject
annotation also serves the same purpose, but the main difference between them is that @Inject
is a standard annotation for dependency injection and @Autowired
is spring specific.
See: https://javarevisited.blogspot.com/2017/04/difference-between-autowired-and-inject-annotation-in-spring-framework.html