JEE的@EJB和Spring的@Autowired有什么区别



JEE@EJBSpring框架的@Autowired之间有什么区别?

  • 这些是同一个吗?

  • 如果没有,的差异是什么

我看到了以下@EJB的定义,它看起来真的很像@Autowired的定义:

企业bean(EJB(是一个服务器端组件,用于封装应用程序的业务逻辑。

业务逻辑是实现应用程序目的的代码。它不起作用显示业务数据或直接在数据库上执行操作。

@EJB用于将EJB注入JEE世界中的另一个EJB
请参阅:我应该使用@EJB还是@Inject

Spring中,通过使用@Autowired进行等效注入
示例:

@Service
public class MyServiceImpl implements MyService {
}
@Controller
public class MyController{
@Autowired MyService myService;
}

@ServiceSpring注释,用于在服务层注释类
其他注释:@Component@Repository@Controller@Service
请参阅:What';这是@Component、@Repository&Spring中的服务注释

我会说:

  • @Component@Repository@Controller&@Service更接近@Stateless@Statefull,并且
  • @EJB@Autowired相似

UPDATE@Autowired告诉Spring框架为您查找依赖项。@Inject注释也有相同的用途,但它们之间的主要区别在于@Inject是依赖注入的标准注释,而@Autowired是特定于弹簧的。请参阅:https://javarevisited.blogspot.com/2017/04/difference-between-autowired-and-inject-annotation-in-spring-framework.html

最新更新