开发者

Updating legacy Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.

Improve this question

I have a Java servlet website, but does not use any frameworks like Spring or even Struts! It does have hibernate in it which it uses along side regular sql. It also has no unit tests. It uses cvs and ant. The server can only run Java 1.4 in the JSP's.

Aside from that, the code is fairly well structured.

Are there good ways to add more modern features to the code while minimizing the risk? It seems like we could add some spring features onto new code. And maybe replace the the cvs and Ant with Subversion and Maven, or perhaps something else.

Would it be possible to have new parts of the site running in s开发者_如何学编程omething like Spring MVC or even JRuby on Rails?


  • the code is fairly well structured

If that is the case, I would start by writing several tests that ensure that current behavior/business stays the same, while you go ahead and introduce Spring in the mix.

  • Would it be possible to have new parts of the site running in something like Spring MVC or even JRuby on Rails

Everything is possible, but since the code is already Java, and as you pointed out "well structured", I would go with Spring.

The easiest place to start is to figure out what depends on what in order to start the "website". Once you have that, you would already have different components (on paper + in the code) that you can draft with a Spring "starter" application context, that you can load with web.xml as:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:META-INF/spring/starter-application-context.xml /WEB-INF/spring/transportes-webflow.xml ... </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

That is before you use any Spring MVC features. Once you have that, see if you can define a domain model for this project. Then you can start converting Servlets to Spring MVC Controllers and Models ( those domains ).

As you move one step at a time, run those tests, to make sure the behavior is still solid. These can be simple JUnit tests, as well as Selenium tests that would ensure that the "website" flow is still intact.

  • It uses cvs and ant

I would recommend to switch your build architecture to Gradle, it does take a bit or a learning curve to wrap your head around accessing everything in a build script (which is a good thing), but it really pays off.

As to CVS, I prefer git, but if you feel strong about SVN, you can switch to that as well. git, in my opinion, became as standard to Version Control System, as Spring to Java development.

  • It does have hibernate in it which it uses along side regular sql

Understand the reasons regular SQL is used. If these are performance reasons, you can use store procedures instead (that you can work with from within Spring). Also see the reason Hibernate is used, as it may bring additional complexity, that you may not need, and would be better off with a simple Spring JdbcTemplate.


@tolitius has covered all bases except that I would suggest that you first add Selenium tests to cover all major use cases before embarking on any of these changes. That will make it easier to add improvements in short iterative cycles.


Why do you need to do any of these proposed things? If it's purely for the sake of being current and using newer frameworks, then I would recommend against it.

I think a good start would be to write unit tests under the current code base to help minimize the risk for future changes. Also, assuming the project structure is not too complicated, the migration to SVN should not be too difficult, and shouldn't require a change to any of the source code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜