Struts2-Full-Hibernate 插件是集成 Struts2 和 Hibernate 的标准方式吗?
Is Struts2-Full-Hibernate plugin the standard way to integrate Struts2 and Hibernate?
我正在开始一个项目,愿意使用Struts2和Hibernate。
我应该使用 struts2-full-hibernate 插件,还是以不同方式集成它们?
在网上搜索我很困惑:这是集成它们的标准方式吗?如果不是,那是标准方式?
简而言之:
- 选择前端的框架(一般是MVC,然后Struts2,JSF2,Spring MVC, 等等...你已经选择了 Struts2. Java EE 6+ 中的标准(不一定是最好的也不一定是最常用的)堆栈是 JSF2);
选择持久性管理器:
JavaEE 6+的标准是JPA 2.0(JSR 317 - Java Persistence API). JPA are just annotations, you need a library implementing them; Hibernate can be used as JPA implementation. Hibernate is not the only JPA provider, but it is the most used one (not necessarily the best one), and hence the most standard. With this configuration, you can structure the application's layers by separating the presentation layer (Struts2 actions) from the persistence layer ,执行CRUD的地方。也不再需要DAO层,因为JPA的EntityManager 是 dao本身。
否则您可以使用 raw Hibernate 及其专有注释(或任何其他持久性管理器),并在在这种情况下,对于 Struts2,您 可以 使用(复古?)Struts2-Full-Hibernate plugin. It simplifies some jobs, but force you to use the OSIV (Open-Session-In-View) (anti)pattern.
选择框架和持久性管理器后,您需要选择 DI(依赖注入)管理器。如果您使用 Java EE 6+,标准是使用 CDI(JSR 299 - 上下文和依赖注入)。在 Java EE 6 之前,或者对于怀旧的开发者来说,Spring 仍然可用。当 Java EE 缺少它时,它是第一个提供 DI / IoC(控制反转)的库。
具体来说,使用 Struts2 您可以:
- 将 CDI 与 Struts2-CDI-plugin;
集成
- 将 Spring 与 Struts2-Spring-plugin.
整合
结论
根据 Java EE,Struts2(而不是 JSF2)的标准配置是:
- Struts2
- Java EE 6+ (CDI + JPA 2.x + EJB 3.x)
- Hibernate 4.x
- Struts2-CDI-plugin
我正在开始一个项目,愿意使用Struts2和Hibernate。
我应该使用 struts2-full-hibernate 插件,还是以不同方式集成它们?
在网上搜索我很困惑:这是集成它们的标准方式吗?如果不是,那是标准方式?
简而言之:
- 选择前端的框架(一般是MVC,然后Struts2,JSF2,Spring MVC, 等等...你已经选择了 Struts2. Java EE 6+ 中的标准(不一定是最好的也不一定是最常用的)堆栈是 JSF2);
选择持久性管理器:
JavaEE 6+的标准是JPA 2.0(JSR 317 - Java Persistence API). JPA are just annotations, you need a library implementing them; Hibernate can be used as JPA implementation. Hibernate is not the only JPA provider, but it is the most used one (not necessarily the best one), and hence the most standard. With this configuration, you can structure the application's layers by separating the presentation layer (Struts2 actions) from the persistence layer ,执行CRUD的地方。也不再需要DAO层,因为JPA的EntityManager 是 dao本身。
否则您可以使用 raw Hibernate 及其专有注释(或任何其他持久性管理器),并在在这种情况下,对于 Struts2,您 可以 使用(复古?)Struts2-Full-Hibernate plugin. It simplifies some jobs, but force you to use the OSIV (Open-Session-In-View) (anti)pattern.
选择框架和持久性管理器后,您需要选择 DI(依赖注入)管理器。如果您使用 Java EE 6+,标准是使用 CDI(JSR 299 - 上下文和依赖注入)。在 Java EE 6 之前,或者对于怀旧的开发者来说,Spring 仍然可用。当 Java EE 缺少它时,它是第一个提供 DI / IoC(控制反转)的库。
具体来说,使用 Struts2 您可以:
- 将 CDI 与 Struts2-CDI-plugin; 集成
- 将 Spring 与 Struts2-Spring-plugin. 整合
结论
根据 Java EE,Struts2(而不是 JSF2)的标准配置是:
- Struts2
- Java EE 6+ (CDI + JPA 2.x + EJB 3.x)
- Hibernate 4.x
- Struts2-CDI-plugin