14 Replies Latest reply on Oct 30, 2006 11:39 AM by Gavin King

    Seam with Spring?

    Mike Stephen Newbie

      Hi,

      Firstly, I love your demo! I think when promoting a new framework that has some web functionality it is vitally important to have a polished, professional looking demo, so well done.

      Also, I'm very glad to see you're using Facelets, nice choice.

      I've been reading a bit about Seam and it seems very good. A couple of questions that I have:

      1) Is it possible to use Spring with Seam, rather than EJBs? I read in some of the documentation that if you use JavaBeans rather than the other component types (Entity Beans, Session Beans), that there would be no transaction management. The reason I ask is that I am now experienced with Spring and would prefer to keep using it while hopefully also benefitting from what Seam has to offer at the same time.

      2) This is a general annotation question really... I personally prefer to work in XML I know this is not fashionable :), but I do find mapping files etc. much easier to read than annotations (was never a fan of xdoclet), so is it possible to use xml instead of annotations? I realise that Seam may not support this yet, so this is more of a long-term question.

      Thanks,

      Mike.

        • 1. Re: Seam with Spring?
          Gavin King Master

           

          Is it possible to use Spring with Seam, rather than EJBs?


          It would be very easy to add support for spring components as a kind of STATELESS component. We have already speculated privately that this is something we might support. I guess you could easily write a patch for this, if we don't get round to it first.

          I read in some of the documentation that if you use JavaBeans rather than the other component types (Entity Beans, Session Beans), that there would be no transaction management.


          That's not quite true. What the docs mean is that there is no *component* demarcated transactions, as there are in EJB. However, if you use SeamManagedPersistenceContextPhaseListener, you will get Seam-managed transactions, with conversation-scoped Seam-managed extended persistence context, which is actually a really nice option. If you're interested, I can give more details about the advantages of this, but it is described in the docs.

          The reason I ask is that I am now experienced with Spring and would prefer to keep using it while hopefully also benefitting from what Seam has to offer at the same time.


          Sure, we don't want people to have to throw away existing code to be able to make the switch. However, a small word of caution: to get the full benefits of Seam, you want to start thinking about componentizing your system into stateful components. So the Spring model of mostly stateless beans can interoperate with the Seam model, but it is not really the same model.


          • 2. Re: Seam with Spring?
            Papick Newbie

            IMHO, using Spring with Seam is not breaking with the main Seam concepts.
            There are still situations where you could prefer to stick to the stateless Spring backend.
            When integrating with JSF, it is enough to add a new variable resolver. Is there a simila concept in Seam?

            Or is it even enough to add the variable resolver as it is done by now?

            • 3. Re: Seam with Spring?
              Gavin King Master

               

              There are still situations where you could prefer to stick to the stateless Spring backend.


              You can easily implement a stateless business layer in Seam....

              When integrating with JSF, it is enough to add a new variable resolver. Is there a simila concept in Seam?


              You can have as many variable resolvers as you like. The Seam variable resolver to resolve Seam components, a Spring resolver to resolve Spring beans, etc....

              • 4. Re: Seam with Spring?
                Papick Newbie

                Hi Gavin, thanks for the reply.

                I saw the statelles layer in seam, its nice. In my special case, I have a architecture ontop of maven2 and spring. Autonomous modules, quite nice.

                Seam does really nice magic in the frontend.
                For me it looks like JSF as it should have been from the beginning, and its the major technology line-up tha Sun failed to provide with Java EE 5.

                "gavin.king@jboss.com" wrote:
                You can have as many variable resolvers as you like. The Seam variable resolver to resolve Seam components, a Spring resolver to resolve Spring beans, etc....


                Yes, thats true for JSF, but what about Seam? Is it that extensible too? Would be *very* interesting to have some Spring beans injected into my contextual web model handled by Seam.

                greetings from germany,

                Papick G. Taboada

                • 5. Re: Seam with Spring?
                  Manuel Gentile Newbie

                  Do you have an example of integration between seam and spring?!??!?!
                  Thanks

                  • 6. Re: Seam with Spring?
                    Todd Smart Newbie

                    Sorry to regurgitate Manuel's question ... however, I'm working with a team that has Spring massively integrated into its framework.

                    Many on the team (myself included) would like to leverage Seam 1.1 ... for the purposes of Validation, Internationalization, Conversation State ... just to name a few.

                    Are there others out there working in a Spring + Seam environment ... or planning to do so?

                    I'd very much appreciate hearing success and/or failure stories ... an example app would be even better!

                    • 7. Re: Seam with Spring?
                      Fady Matar Novice

                      How would the spring framework integration enhance JBoss Seam? Session beans in JBoss Seam are being used for transaction management.
                      I don't see any benifit of integration the spring framework except for replacing the transaction managemnt of Session Beans and use Hibernate POJOs instead of Entity beans.

                      I believe the complexity and inter-dependency of frameworks needt to be reduced, required functionalities of Spring can be embedded into JBoss Seam easily, the framework is quite flexible and made me drop a similar framework I've been developing that used Spring and WebWork back then

                      • 8. Re: Seam with Spring?
                        adambrod Newbie

                        The easiest way to integrate Spring and Seam, that I've found, is to use a JSF variable resolver and only have the dependencies go from Seam to Spring.

                        In the presentation tier, you can use Seam to manage your controllers (and conversations and lots of other good stuff). In the backend tier you can use Spring to manage your stateless services (Daos, Repositories, any Service). Then, you can inject your services into your Seam controllers using the Seam @In(#{mySpringService}) notation. Seam recognizes JSF expressions.

                        Spring ships with a JSF variable resolver. You just need to register it in your faces-config.xml.

                        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>


                        You can use Spring to manage your services (instead of using Stateless Session beans, for example), you can use Seam to manage your controllers (aka JSF managed-beans) and conversations. So the Seam components can reference Spring components, but Spring components cannot reference Spring components.

                        I hope this helps.

                        • 9. Re: Seam with Spring?
                          Gavin King Master

                          Yes, that sounds like an excellent strategy - want to write up a Wiki page with code examples?

                          Another thing that would be very useful for people using Seam with Spring would be to be able to inject a Seam-managed persistence context (Session or EntityManager) into a Spring DAO. This has got to be very easy to set up, is my guess (just write a Spring factory method that looks up the Seam PC).

                          Does someone want to figure out the details of that, and wikify it?

                          • 10. Re: Seam with Spring?
                            Gavin King Master

                            Actually, it should be trivial to write a generic Spring factory method to look up ANY Seam component.

                            • 11. Re: Seam with Spring?
                              adambrod Newbie

                              Sure. How can I post a new page to the wiki?

                              • 12. Re: Seam with Spring?
                                adambrod Newbie

                                Nevermind, here is my wiki entry on Spring and Seam integration. Anybody please add to this where it makes sense. http://wiki.jboss.org/wiki/Wiki.jsp?page=SpringAndSeamIntegration

                                • 13. Re: Seam with Spring?
                                  Martin Henderson Newbie

                                  Hey folks,

                                  Did anyone decide to do a lookup to get the PeristenceContext in a factory method? I'd like to do this, but am not 100% sure where to start.

                                  Is it possible to get the PC from the Contexts class using thelookupInStatefulContexts() method? or am I totally on the wrong track?

                                  hope you can help,

                                  Marty

                                  • 14. Re: Seam with Spring?
                                    Gavin King Master

                                    You should use Component.getInstance(pcName)