JEE的@EJB
和Spring框架的@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;
}
@Service
是Spring注释,用于在服务层注释类
其他注释:@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