6 Replies Latest reply on Nov 9, 2010 11:00 AM by Gab Aldian

    Migration from Spring to Seam

    Gab Aldian Newbie


      I am working on the prototype of a project. Originally, I worked with JSF and Richfaces / Spring / Hibernate, but it eventually appeared that Seam should be better than Spring for what I intend. My goal is to totally replace Spring by Seam, but I have issues translating my application-context.xml file into Seam configuration files and annotations.

      Actually, I am not very fan of annotations, I still feel that having all discribed in xml files is better, because in a few xml files I can see the whole configuration, but I will do my best using annotations.

      For example, I would like to know how to describe the folowing bean to seam:

      <bean id="sessionFactory"
                <property name="mappingResources">
                <property name="hibernateProperties">
                          <prop key="hibernate.dialect">
                          <prop key="hibernate.show_sql">true</prop>
                          <prop key="hibernate.cglib.use_reflection_optimizer">
                <property name="dataSource">
                     <ref bean="dataSource" />

      Is there any page which explains how to do that? I presume I am not the first one to ask.. Thank you very much :)

        • 1. Re: Migration from Spring to Seam
          Leo van den berg Master


          have you seen the (FREE) downloadable Spring chapter of Seam In Action at Manning.com. It explains exactly what you want to do.


          • 2. Re: Migration from Spring to Seam
            Gab Aldian Newbie

            Leo van den Berg wrote on Nov 04, 2010 10:00:

            It explains exactly what you want to do.

            I am sorry, but it doesn't. It explains how to build an hybrid spring-seam application, when I want to totally remove Spring and completely replace it by Seam.

            BTW, I have been reading a lot since I posted there and almost found how to do : put all the hibernate stuff in the file hibernate.cfg.xml, and follow these directives: My Link.descriptor 

            I also used this explanation My Link.descriptor to try to translate my beans into component (replacing "bean id" by "component name" at all occurences, for example like this:

            <component name="databaseAccess" class="dao.DatabaseAccess">
                      <property name="sessionFactory">#{hibernateSessionFactory}</property>

            But the injection doesn't seam to work, I have lots of "java.lang.RuntimeException: Could not create Component" caused by "java.lang.IllegalArgumentException: type argument not a class"

            • 3. Re: Migration from Spring to Seam
              Leo van den berg Master


              I few days ago I answered a comparable answer. There is a vital thing you must remind about spring in Seam. When there is a dependency on the spring container (via init/ depends on etc) you must subclass the bean and add create and unwrap annotations. I don't know how complex your database acces is, but I would certainly replace it with the Seam managed manager, not only for its added value, but to prevent further problems.


              • 4. Re: Migration from Spring to Seam
                Gab Aldian Newbie

                I am sorry, but I don't think it can help me. As I said, I don't use Spring anymore. So there is no dependency. As for my class DatabaseAccess, it is nothing but a class which calls hibernate methods for the given sessionfactory, for example, here is one of its methods:

                     /* (non-Javadoc)
                      * @see dao.IDatabaseAcces#persist(entity.IEntity)
                     public void persist(IEntity transientInstance) throws RuntimeException{

                It has no interest but allowing an easy mock.

                Now let's get down to business. What I am asking is very simple:
                In spring, we can for example have this in the file applicationContext.xml:

                <bean id="toto" class="dao.GenericEntityHome">
                     <property name="classtype">

                It specifies that when a reference to the bean named toto is needed, an instance of the class dao.GenericEntityHome will be created, and the method setClasstype(entity.Toto) will be called for this instance.

                I took a look to the documentation of Seam and wrote the folowing in the file components.xml:

                <component name="toto" class="dao.GenericEntityHome">
                     <property name="classtype">

                I have tried a lot of variations, to the point I am almost running out of options and patience, but I always have the exception:

                java.lang.RuntimeException: Could not create Component: toto
                Caused by: java.lang.IllegalArgumentException: type argument not a class

                My one and only question : where I am wrong? As for the reason why I need to do this, I will explain it in another thread.

                • 5. Re: Migration from Spring to Seam
                  Leo van den berg Master


                  I suspect that the argument you're providing is not properly transformed to the type you need. Looking at the error the property is of type Class and I think it is trying it as a String. You can put an additional type attribute on the property element to provide the exact type you want.


                  • 6. Re: Migration from Spring to Seam
                    Gab Aldian Newbie

                    Thank you very much, all errors have vanished. But I don't know if the problem is really solved because I am confronted with a lot of Hibernate exceptions, so I still can't test if the whole thing really works