• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Migrating app from spring 2.5 to spring 4.1 mvc

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have an app built on spring mvc 2.5 , that i need to migrate in spring 4.1 . Since i am using spring after almost 6 years , i see that spring 4.1 is changed a lot .
In my app onSubmit methods are returning ModelView while in spring 4.1 methods return string. But there is provision of returning MV too.
I want to keep it same and want to return MV . What do i need to return MV ?
Also there was provision in 2.5 to showForm in case there are form level error like invalid user name etc. How can i do that in spring 4.1 ?

Below is the code from exiting spring 2.5 app.

Please let me know if there is any sample example that validates Form submission.

Thanks .

 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have replaced all spring jars to 4.1 . and changed .xml files according to 4.1
Now i am getting below error .

SEVERE: Servlet.service() for servlet [BlueClouds] in context with path [/BlueClouds] threw exception [No adapter for handler [com.BlueClouds.web.LogonController@4cb25652]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler] with root cause
javax.servlet.ServletException: No adapter for handler [com.BlueClouds.web.LogonController@4cb25652]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler.

In my <app>-servlet.xml i have added
<context:annotation-config/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>


and removed SimpleURlHandler . since in 4.1 it does it automatically.

If any one can provide me little idea then please let me know .

Thanks in advance.

 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am not very happy with this new version of 4.1 . It is very camouflaged kind of framework . While in 2.4 every thing was clear and visibly working . Till now not even able to load initial web page . Annotations are hell .No proper documentation ... Anyway .. All its features i can code in java , instead of leveraging its jars ... so would go with old 2.4 spring only ... Thanks .
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find comprehensive reference documentation for Spring 4.1 on Spring's website, including everything about Spring Web MVC.

You just feel this way because you're not as familiar with Spring 4.1 as you are with 2.5.

You are not required to use annotations with Spring 4.1, you can also use Spring XML configuration files to define your beans. Many people prefer annotations above having XML configuration files, though.
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IT is not even able to map simple URL .
Same application run without any issue in spring 2.4 . Now in 4.1 they have messed with annotations + XML config ( as you said ) . Deprecated many handler classes. No clear visibility what is happening behind the scenes. A simple servlet application would be much better than that.

now after 1 week i came to know if mvc:annotations is given in app-servlet.xml then need to remove bean tags . As a programmer i would not use something which is not clear in understanding to me . Apologies.

Thanks for your reply .
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am able to bring home page by replacing SpringMVC libs from 2.5 to 4.1 . It comes up well.

The thing is i want to use spring mvc 4.1 features . Like it supports the return of string instead of MVC . That i am unable to do till now .
In my controller it still returns MVC Object only . then only home page comes .


But i when i return "logon" it doesn't load home page .

Then my motive to migrate it to spring 4.1 is getting defeated .. Any suggestions ?

Thanks for the help .

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The thing is i want to use spring mvc 4.1 features . Like it supports the return of string instead of MVC.But i when i return "logon" it doesn't load home page.


This is not a new feature introduced in 4.x. It was available even in 2.5 using InternalResourceViewResolver, and likely in even earlier versions.

Anyway, what you need is an InternalResourceViewResolver bean. It resolves a string like "logon" to a web application view resource like 'WEB-INF/views/logon.jsp'.
Use InternalResourceViewResolver only if your view resources conform to this convention. Otherwise, you should use one or more of the other view resolvers, and chain them.
I recommend reading up all the sections related to view resolvers starting here.

From the discussion so far, I felt that you are not sure why you are upgrading to 4.1. If there is no definite goal and your existing code is all working fine with 2.5, then I suggest keeping as much of your code unchanged - which should be doable, since spring has maintained good backward compatibility over versions - and solve only problems that may come up. Moving entire codebase wholesale to annotation based or something like that will probably not add any value to your business or your customers.
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason to migrate to 4.1 is there are few more modules that have to be developed in this app. For those modules i want to leverage Multipart file Upload , Caching enhancements , Java Mail API that comes in handy in 4.1 . Also i see many things have become easier by use of annotations and thus reducing app-servlet.xml . 4.1 supports multiple URL mapping with same controller . In 2.5 i need to extends MultiViewController in order to do so , also need to map action in app-servlet.xml .

 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it InternalResourceViewResolver or org.springframework.web.servlet.view.UrlBasedViewResolver ?
In old spring 2.5 the former is used and i am using MVC there , but in 4.1 i changed to latter one to resolve string returns. But it is not working .
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
InternalResourceViewResolver is a subclass of UrlBasedViewResolver, and both behave the same way. The former has a few additional attributes to control how views are rendered.
"It is not working" is not very helpful to us to answer questions. If something is not working in Spring, you need to show us the relevant context XML or configuration, the controller code and directory structure where your views are stored.
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , My problem got resolved . I am able to get back the jsp pages by returning string.
It is working fine with both the View Resolver classes.

Thanks for answering .
 
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic