开发者

Is it possible\advisable to refactor a Spring MVC application to use another MVC framework?

I am just getting started using Spring and am currently reading Spring in Action to ramp up. In citing the benefits of Spring vs. EJBs, the book makes the statement:

"With Spring, components are typically not required to implement, extend, or use any Spring-specific classes or interfaces, making it possible to reuse the components anywhere, even in the absence of Spring."

My application is currently using Spring MVC. I can see how the above statement holds true for my application's business logic, as the use of dependency injection has completely decoupled our beans from the Spring framework. But what about the MVC stuff, which in this case is a web application? I am curious as to whether it would be possible to swap out Spring MVC in my application with another MVC framework in the future.

My question is twofold:

1) Should I view the web tier as tightly coupled to the Spring framework and assume that a change in my MVC would necessitate the creation of a new web application to support it?

2) If not, what would be involved in decoupling the web application from Spring? I can already guess that in the absence of the Spring framework, all of the annotations would need to be removed from the controllers and the associated code would need to be refactored to support the new M开发者_如何学JAVAVC framework.

I am particularly interested in the insights of anyone who has been through this process.


Good question. As you rightly pointed out, the MVC framework does tend to couple your code to the Spring API much more closely than with business-logic layers.

This is pretty much unavoidable, although to a much lesser extend than it is with Spring 3, where annotations are heavily used to map requests to controllers, and so on. The coupling of method parameters and return values to the Spring API is much reduced. The controllers can express themselves in terms of their business logic.

However, in order to get any sort of expressive power from Spring MVC, some use of its API is usually going to be involved.

So to answer your question, while the coupling from the Spring API to your controller code is pretty minimal, it is there, and would need to be removed. However, since it's a very non-invasive API, there should be few design compromises in your code, making it easier to adapt to another framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜