Showing posts with label controller. Show all posts
Showing posts with label controller. Show all posts

1 November 2012

How to solve problem "The hierarchy of the type XXX is inconsistent" in project that uses spring framework

Solution for Eclipse/Spring framework 3.1.3

STORY:
So you create a shiny new project using spring framework  in eclipse and you based on some example "Hello World" found on internet and yo copy all stuff BUT Eclipse complain that:

"The hierarchy of the type HelloWorldController is inconsistent" near  to "extends  AbstractController ".

(Usually this error come with another: "The type org.springframework.beans.BeansException cannot be resolved. It is indirectly referenced from required .class files" ).

and you ask question WTF ... which stands for what a terrible failure ...

SOLUTION:

no worries.

It means your "copy and paste" skills are rubbish,because you forgot paste one of the libraries needed for spring framework
(One of the core library is missing .You need add to your librarys,maven or whatever you use for library managment)

In my case i forgot to add beans library called  org.springframework.beans-3.1.3.RELEASE


btw.

 1) if anybody need working hello world example for spring framework 3.0.5 and higher
http://www.dzone.com/tutorials/java/spring/spring-mvc-tutorial-1.html

 2)Here you have nice explanation of what inconsistent hierarchy error means in general case :    http://java.syntaxerrors.info/index.php?title=Inconsistent_hierarchy

Note to myself :
"The hierarchy of the type xxl is inconsistent"

if something in the hierarchy is broken(not exist etc.).
For example, if you have 


 public abstract class Size implements NonExistentInterface { 

   (...)

}
 public abstract XXL extends Size {

     (...)  

}


then you will get an error in Foo.java saying that the hierarchy of the type Foo is inconsistent.


(NonExistentInterface is an interface that doesn't exist .)

Worth to know: During crap nature of Eclipse it can be  displayed if your imports are out of sync,  hit 'Refresh' (F5) in project

28 July 2011

How to inject parameter to controller in spring 3?

Solution for Spring 3 (Annotations)

In many tutorials you can find how to add parameter to service and it looks is , it is and ...  it doesn't work when you trying apply "easy successful receipe" to controller, so shit hit the fun and you feel screwed up.

However... solution for your problem is still simply.
You need:
1)Set parameter in META-INF/context.xml
 <?xml version="1.0" encoding="UTF-8"?>
 <Context displayName="Another awsome program">
 <Parameter name=" param/naughty/url " value="http://pastor.ovh.org"/>
 (... bunch of other stuff ...) 
</Context> 
2) In your marvellous controller
package org.ovh.pastor.mvc.controller; 
 @Controller
public classAwsomeController  {
(  ... bunch of other stuff ...) 
private @Value("${param/naughty/url}") String doggyWebsite;  
 public void setDoggyWebsite ( String doggyWebsite ) {
this. doggyWebsite = doggyWebsite ;
 } 
(  ... bunch of other stuff ...)   
}

 Little explanation of most important line:

  private @Value("${param/naughty/url}") String doggyWebsite;

where :
  •  private  - modifier
  • @value - is a lovely annotation that contain information where is parameter 
  • String -  data type 
  •  doggyWebsite  - vairable name
     

Hope , it helps . Keep smiling and pray that someday spring will be easier , better explained by examples.

8 April 2011

How to redirect to other controller in spring 3 (that

Solution for spring 3.0.x:

You controller done his job less or more successfully and now you will would love to share your data with other controller to do his job.
What you need to is simply on return you need add redirect:  (with path) for example:
      return "redirect:/secretpage/lollypop.html";

so your controller will looks :





@Controller
@RequestMapping("secretForm.html")
public class SecretController {
  (... some private pleasue or business logic ...)

@RequestMapping(method = RequestMethod.POST)
  public String processForm(HttpSession session, HttpServletResponse response,@Valid SecretForm secretForm, BindingResult result)  Model model) {
(... your private pleasue or business logic   ...)
       return "redirect:/secretpage/lollypop.html";
}

what happen ?
SecretController will send view to client and say "Hello folk! This is view,but can you go to this page ( (page)/secretpage/lollypop.html ",please? Client will answer "no problem" and send request to dispatcher with question "any idea what to do with this ?" and then other spring stuff happen.