使用 Hibernate / Guice / Wicket 替换 Hibernate /Spring / Spring MVC 堆栈

发布于 2024-12-03 03:11:30 字数 227 浏览 1 评论 0原文

我有一个使用 Hibernate / Spring 和 Spring MVC 的应用程序,但作为学习和比较差异的动机,我想将该应用程序移植到 Hibernate / Guice / Wicket。

我的问题非常基本,但我从哪里开始呢?我应该先替换 Spring 层,然后替换 Spring MVC 层吗?

两者可以在同一环境中工作吗?这样我就可以从编辑一个控制器/视图开始,然后进行扩展,我该如何做到这一点?

I have an application which are using Hibernate / Spring and Spring MVC, but as a motivation to learn and also compare the differences I want to port the application to an Hibernate / Guice / Wicket.

The questions I have are pretty basic, but where do I start. Should I start with replacing the Spring layer, then the Spring MVC layer?

Can the two work i the same environment, so that I can start with editing just one controller/view and then expand, and how do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的快感 2024-12-10 03:11:30
  1. 从视图开始:

    无论如何,如果没有 Spring,Spring MVC 将无法工作。由于其他层不依赖于其 API(嗯,至少不应该),表示层应该是最容易更改的(尽管需要花费大部分精力,因为它将包含一个完整的 API)重新实现)。

  2. 春天之后:

    a) 如果您不使用 Spring 的太多实用程序类(*Template、*DaoSupport 等)或基础设施(事务管理、安全性),迁移到 Guice 可能需要重写(XML 或注释) -based)Guice 模块/注释中的配置,因为纯粹的依赖注入(如果不可移植)几乎是直接在框架之间映射的。

    b) 如果您确实使用 Spring 的实用程序类和基础设施(您可能会这样做,因为这就是使用 Spring 而不是无增值的另一个依赖注入容器的全部意义...),你必须以某种方式将它们迁移到 Guice。如果您打算逐步执行此操作,您可以在两者之间寻找一些集成(可能使用 Guice 的 Spring 基础设施),并且在迁移依赖项后,切换到 Guice 本地拦截器实现(以及测试、测试、测试,因为行为上的微小差异可能会破坏您的应用程序)。 这个其他问题可能会提供一些关于此的提示。

  3. 然后,休眠:

    由于您将保留 Hibernate,因此其配置不应受到转换的影响。当您将基础架构和配置迁移到 Guice 时,只有其引导程序会发生变化。如果可以避免的话,我不建议保留两个并行的 SessionFactory。

  1. Start with the view:

    Spring MVC won't work without Spring anyway. And since other layers don't depend on its API (well, shouldn't, at least), the presentation layer should be the easiest to change (although the one that will take most of the effort, since it will consist in a complete reimplementation).

  2. Go after Spring:

    a) If you don't use much of Spring's utility classes (*Template, *DaoSupport, etc.) or infrastructure (transaction management, security), migrating to Guice would probably be a matter of rewriting (XML- or annotation-based) configuration in Guice modules/annotations, since pure dependency injection, if not portable, is pretty much directly mapped between the frameworks.

    b) If you do use Spring's utility classes and infrastructure (which you probably do, since that's the whole point of using Spring instead of no-value-added-yet-another-dependency-injection-containers...), you'll have to migrate them to Guice somehow. If you plan to do this incrementally, you could look for some integration between the two (probably using the Spring infrastructure from Guice), and after you migrated the depedencies, switch to Guice-native interceptor implementations (and test, test, test, since little differences in behavior could break your application). This other question may provide some tips on this.

  3. Then, Hibernate:

    Since you'll be keeping Hibernate, its configurations shouldn't be affected by the transition. Only its bootstrap will change when you migrate your infrastructure and configuration to Guice. I don't recommend keeping two parallel SessionFactories, if you can avoid it.

£烟消云散 2024-12-10 03:11:30

从一种框架逐渐过渡到另一种框架对于开发来说似乎是可能的,但对于生产来说则不然。您在单个环境中进行逐页替换时必须面对的问题。

  1. 网址映射

    springMVC+spring+hibernate 和 wicket+guice+hibernate 的引导是使用 url 模式完成的。您必须告诉服务器 springmvc 或 wicket 是否会处理该请求。

    您应该使用根模式完全分离上下文。因此,在迁移阶段,URL 将很难协调。 spring 版本无法引用 urls 版本 wicket。

  2. 数据同步

    两个休眠映射将并行运行。不要使用缓存并在每次页面请求时重新加载所有信息,以确保数据同步不会出现问题。

该解决方案的缺点是由于双负载休眠映射而导致服务器的启动时间延长。

您应该首先在 web.xml 中添加 wicket-guice 应用程序:

<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>com.app.web.guice.MyGuiceServletContextListener</listener-class>
</listener>

The gradual transition from one framework to the other seems possible for the development but not for production. The issues you'll have to face doing a page by page replacement in a single environment.

  1. url mapping

    The bootstrapping of springMVC+spring+hibernate and wicket+guice+hibernate is done using url patterns. You have to tell the server if springmvc or wicket will serve the request.

    You should completely separate the contexts by using a root pattern. Therefore, during the migration phase, the urls will be difficult to reconcile. The spring version can not reference urls version wicket.

  2. data synchronization

    Two hibernate mappings will operate in parallel. Do not use cache and reload all the information on each page request to be sure not to have problems with data synchronization.

A disadvantage of this solution is the starting time of the server due to the double load hibernate mapping.

You should start by adding a wicket-guice application in your web.xml:

<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>com.app.web.guice.MyGuiceServletContextListener</listener-class>
</listener>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文