简体   繁体   English

使用非弹簧Web应用程序可以实现并行Spring-MVC应用程序吗?

[英]Is a parallel Spring-MVC application possible with a non-spring web app?

I have a Tomcat application pretty huge. 我有一个非常庞大的Tomcat应用程序。 Very ctitical to the business (real money making). 非常适合商业(真钱赚钱)。 But it is legacy Java code. 但它是遗留的Java代码。 Meaning, JSP (with a lot of Javascript, Java code), Servlets (with thousands of lines of code) and so on. 意思是,JSP(有很多Javascript,Java代码),Servlets(有几千行代码)等等。 We want to get away from this crappy code. 我们希望摆脱这个糟糕的代码。 Now a request has come for another application (different purpose, different functionality). 现在已经有另一个应用程序(不同的目的,不同的功能)的请求。 We need it at another context root /NewApp lets say under the legacy application directory structure. 我们需要在另一个上下文root / NewApp让我们说在遗留应用程序目录结构下。 Like a mini-site. 像一个迷你网站。 It will have a different URL, could even be serving a few virtual hosts. 它将具有不同的URL,甚至可以为几个虚拟主机提供服务。

We dont want to extend the Legacy code. 我们不想扩展Legacy代码。 We want to move to better technologies and better way of doing things. 我们希望转向更好的技术和更好的做事方式。 We are strongly for Spring (tiles, jackson etc. etc.) and all the things it has to offer including portlets. 我们强烈要求Spring(tile,jackson等等)以及它提供的所有东西,包括portlet。 So, we are thinking of possibilities of bringing in DispatcherServlet/ContextLoaderListener/configLocation etc into the legacy app web.xml and have a spring app side by side. 因此,我们正在考虑将DispatcherServlet / ContextLoaderListener / configLocation等引入遗留应用程序web.xml并将弹簧应用程序并排放置的可能性。

The main reason is the new app has serious dependencies on the legacy services and libraries. 主要原因是新应用程序严重依赖于遗留服务和库。

  1. Is this peaceful coexistance possible? 这种和平共处是否可能?
  2. What are the challenges that we could possibly face? 我们可能面临哪些挑战?
  3. Can you please point us to any example configurations? 能否请您指出任何示例配置?

We cant separate them out unfortunately. 不幸的是,我们无法将它们分开。 Appreciate your insight into this. 感谢您对此的见解。

Thank you!! 谢谢!!

We went through a similar use case some time ago, while migrating moderately large application from EJB 2.1 to Spring. 我们在不久前经历了一个类似的用例,同时将适度大的应用程序从EJB 2.1迁移到Spring。 For a great deal of time Spring beans were coexisting with EJBs. 在很长一段时间内,Spring bean与EJB共存。 We were choosing leafs in the dependency hierarchy first, so that Spring beans depended on EJBs but not the other way around. 我们首先在依赖关系层次结构中选择了叶子,因此Spring bean依赖于EJB而不是相反的方式。 This was working beautifully, beans were calling EJBs like any other bean thanks to Spring proxies and dependency injection. 这很漂亮,由于Spring代理和依赖注入,bean像任何其他bean一样调用EJB。

In the same application we had both Struts 1 and Wicket for new pages (damn, there were even Wicket iframes inside Struts pages!), we even had legacy JDBC-based persistence solution side by side with JPA. 在同一个应用程序中,我们同时拥有Struts 1和Wicket用于新页面(该死的,Struts页面中甚至还有Wicket iframe!),我们甚至将原有的基于JDBC的持久性解决方案与JPA并排。 It all worked well. 一切都运作良好。

Things to keep in mind: 要记住的事情:

  1. It's still one application, watch out for back-end caching 它仍然是一个应用程序,注意后端缓存

  2. Treat legacy services like Spring beans. 处理像Spring bean这样的遗留服务。 Build some bridges/proxies/adapters, inject legacy services just like you inject other beans. 构建一些桥/代理/适配器,注入遗留服务,就像注入其他bean一样。 Do not depend on legacy APIs (I imagine some singletons, factories, JNDI lookups) 不依赖于遗留API(我想象一些单身人士,工厂,JNDI查找)

  3. Testing borders between old and new will be hard, prepare for a lot of mocking. 测试新旧之间的边界将很难,为很多嘲弄做准备。

  4. Think about web security, can you integrate both "applications" easily? 考虑一下Web安全性,您可以轻松地集成两个“应用程序”吗?

  5. Let's face it, you'll never completely rewrite old code to new technologies. 让我们面对现实,你永远不会完全将旧代码重写为新技术。 By that time new technologies will become old as well and new developers will come in. But try improving the quality of old code bit-by-bit every time. 到那时,新技术也将变得陈旧,新的开发人员将会加入。但是每次都要逐步提高旧代码的质量。 Refactoring can do miracles! 重构可以创造奇迹!

There is nothing special with configuration. 配置没什么特别之处。 It's a misunderstanding that Spring has to rule your whole application. 这是一个误解,Spring必须统治整个应用程序。 It can be used as a lightweight, thin add-on, living next to the rest of your application. 它可以用作轻量级,轻薄的附加组件,与您的应用程序的其余部分相邻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM