6

I am developing spring-hibernate-jsf application but i dont understand the difference between a managedbean and a spring controller. I think managedbeans work like controllers. Is there any advantage of using controller or managedbean?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Turgut Dsfadfa
  • 775
  • 6
  • 20
  • 42

1 Answers1

1

Managed Beans provides services and are used as model for UI components. Controllers are request/response components like Servlets.

JSF is a component based web framework & Spring is a DI framework. JSF & Spring manages their own beans, so to reference ManagedBeans and inject in them you need to mark JSF ManagedBeans as Spring Controllers using @Controller annotation.

If you are thinking of replacing one with other, then no you have to use both of them if you want to use both Spring & JSF together.

The Student
  • 27,520
  • 68
  • 161
  • 264
Abdullah Shaikh
  • 2,567
  • 6
  • 30
  • 43
  • i just changed my managedbeans to controller(i just add @controller annotiation and delete @managedbean) and it gives "exampleController resolved to null...". – Turgut Dsfadfa Apr 08 '13 at 13:32
  • You need to keep both `@ManagedBean` and `@Controller` annotations, for JSF and Spring respectively. – Abdullah Shaikh Apr 08 '13 at 14:00
  • I would use managed bean only as *controller* for the UI interface and use Spring for DI and classes injection. Still, if you would work in a Java EE environment, it would be better to use EJB instead of Spring (and maybe JPA implemented by Hibernate). – Luiggi Mendoza Apr 08 '13 at 14:29