2

This text is from the book called Core Java Server Faces:

It is a historical accident that there are two separate mechanisms, CDI beans and JSF managed beans, for beans that can be used in JSF pages. We suggest that you use CDI beans unless your application must work on a plain servlet runner such as Tomcat. The source code for the book comes in two versions, one with CDI beans (for Java EE 6 application servers) and one with JSF managed beans (for servlet runners without CDI support).

My question is:

If I use the Spring Framework, and a Tomcat Server, will I need to use one of the beans mentioned above, or does Spring Framework come with its own bean implementations?

As far as I know, Spring Framework supports Dependency Injection. Does it support it if I run the application on Tomcat? Does it mean that I will be using neither the CDI beans nor the JSF Managed means mentioned in this book?

Thank you.

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

1 Answers1

2

talking about container is more correct than bean implementation. Yes Spring comes with its own container. In fact you can see spring frameworks as a kind of alternative to the full Java EE stack.

Using Spring DI and CDI together has about no interest but you still can use JSF with spring on tomcat although if i would advise you to switch to a Java EE 6 web profile server instead of spring in this case.

Spring comes with is own view framework implementation named spring mvc.

All of this can run perfectly on any servlet container (jetty tomcat etc...) on condition that you provide associated dependencies ofc.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Gab
  • 7,869
  • 4
  • 37
  • 68
  • 2
    no a managed bean is a simple pojo (plain old java object) annotated with metadata `@SomeAnnontation`. The container is the object (framework / set of feature - call it as you want) which manage those beans. It will detect annotation and handle it with appropriate behavior (like @transactional will result in container opening transaction, executing annotated method and properly commit/rollbacking transaction after method execution). What's called Dependecy Injection is the fact the container instanciate and manage all beans lifecycle and inject it inside each others using annotations(@inject). – Gab Apr 13 '13 at 00:19