5 Replies Latest reply on Oct 9, 2008 10:47 PM by Guillaume Jeudy

    Seam Spring IllegalArgumentException

    Matt Higgins Newbie
      I have recently started a Seam project an integrated a legacy spring project in. Seam successfully starts the Spring container etc.. I see my bean definitions are loaded. For a simple test I wrote a an interface and iml

      package com.smartdestinations.service;

      public interface BeanOne {
           public String sayHello();
      }

      package com.smartdestinations.service.impl;

      import com.smartdestinations.service.BeanOne;

      public class BeanOneImpl implements BeanOne {
           
           public String sayHello(){ return "Hello"; }

      }

      I then defined this bean in my applicationContext


      <bean id="beanToSeam"
          class="com.smartdestinations.service.impl.BeanOneImpl">
          <seam:component/>     
      </bean>



      Next I wrote a simple backing bean / component.
      package com.vo.pt.session;

      import java.util.List;

      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;

      import com.smartdestinations.service.BeanOne;
      import com.smartdestinations.service.impl.BeanOneImpl;

      @Name("springTest")
      public class SpringTest {
           
           @Logger Log log;
           @In("beanToSeam")
           public BeanOne beanToSeam;
           
           public void sayHello(){
                //uids = categoryService.findAllUids();
                log.info(beanToSeam.sayHello());
                
           }
      }


      I get the following exception when the page action is executed.

      Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection: SpringTest.beanToSeam on: com.vo.pt.session.SpringTest with value: class com.smartdestinations.service.impl.BeanOneImpl_$$_javassist_16
           at org.jboss.seam.util.Reflections.set(Reflections.java:79)
           at org.jboss.seam.Component.setFieldValue(Component.java:1788)
           ... 71 more
      Caused by: java.lang.IllegalArgumentException
           at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
           at java.lang.reflect.Field.set(Field.java:656)
           at org.jboss.seam.util.Reflections.set(Reflections.java:64)
           ... 72 more



        • 1. Re: Seam Spring IllegalArgumentException
          Chris Phillipson Newbie

          Try


          @In("#{beanToSeam}")
           public BeanOne beanToSeam;



          in your bean.


          Make sure you have...


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



          in faces-config.xml.


          See here for more details.


          Cheers,
          Chris.

          • 2. Re: Seam Spring IllegalArgumentException
            Matt Higgins Newbie
            hay Chris thanks for the response. I tried that with the same result. I have also checked out that chapter of the book and was using it as reference as well as this one http://www.manning.com/dallen/SeamIACH15_bonus.doc . One thing I did notice was the example in the seam distribution where using war deployments I am using an ear, could that be an issue ? I have all my spring services and seam components deployed to the jar right now i.e.

            project.ear/
                project.jar/
                       allMyClasses/
                project.war/

            • 3. Re: Seam Spring IllegalArgumentException
              Guillaume Jeudy Master

              hey matt,


              I'm using spring/seam integration in my project. You don't need:


              <bean id="beanToSeam"
                  class="com.smartdestinations.service.impl.BeanOneImpl">
                  <seam:component/> 
              </bean>
              



              just put:


              <bean id="beanToSeam"
                  class="com.smartdestinations.service.impl.BeanOneImpl">
              </bean>
              



              then as Chris pointed out use:


              @In("#{beanToSeam}")
               public BeanOne beanToSeam;



              To inject your spring bean in your seam component. I never had to use seam:component so i'm not sure what you would benefit from it.

              • 4. Re: Seam Spring IllegalArgumentException
                Matt Higgins Newbie

                I am not sure if I will need it either but it did not appear to be much work and I could control the scope of the spring beans. Anyway I backed all that off and just used the EL resolver method and it was also a no go any other thoughts ?


                • 5. Re: Seam Spring IllegalArgumentException
                  Guillaume Jeudy Master

                  Not sure at this point it should work. What is the stacktrace you are getting ? Can you also provide relevant config snippets?


                  Maybe your deployment packaging is causing the problem but I would have trouble believing this, where do your SpringTest seam component and BeanOneImpl spring bean reside ?


                  Both in the EAR lib ?


                  I would expect you bootstrap the spring container from your Seam components.xml right ?