Announcement Announcement Module
Collapse
No announcement yet.
Introductions (Target name cannot be null when refreshing!) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Introductions (Target name cannot be null when refreshing!)

    I am trying to implemet introductions. But I ve stuck with problem: when I run application I ve got message error: "Target name cannot be null when refreshing!".
    Could you point where is a problem ?

    I dont' clearly understand how "Course" will be extended in runtime. I mean how or using what can I access extended Course object from ProxyFactoryBean? And how to manipulate extened object (I want to execute getLastModifiedDate() method) if I would no have extened interface, because Corse object would be still the same.

    Code:
    public class HelloApp {
    
     public static void main(String[] args) throws Exception {
            ApplicationContext context = new FileSystemXmlApplicationContext("introduction.xml");
     Course course = ( (Course) context.getBean("course")); // problems comes here
      corse
    
    
     }
    }



    Code:
    <beans>
        <bean id="courseTarget"
            class="com.springinaction.service.training.Course"
           singleton="false">
        </bean>
    
        <bean id="auditableMixin"
            class="com.springinaction.service.training.AuditableMixin"
            singleton="false"/>
        <bean id="auditableAdvisor" class="org.springframework.aop.support.DefaultIntroductionAdvisor"
            singleton="false">
            <constructor-arg>
                <ref bean="auditableMixin"/>
            </constructor-arg>
        </bean>
        <bean id="course"
            class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyTargetClass">
                <value>true</value>
            </property>
            <property name="singleton">
                <value>false</value>
            </property>
            <property name="proxyInterfaces">
                <value>com.springinaction.service.training.Auditable</value>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>auditableAdvisor</value>
                </list>
            </property>
            <property name="target"  >
                <ref bean="courseTarget" /> 
            </property>
        </bean>

    Code:
    public class AuditableMixin implements IntroductionInterceptor, Auditable &#123;
        public boolean implementsInterface&#40;Class intf&#41; &#123;
            return intf.isAssignableFrom&#40;Auditable.class&#41;;
        &#125;
    
        public Object invoke&#40;MethodInvocation m&#41; throws Throwable &#123;
            if &#40;implementsInterface&#40;m.getMethod&#40;&#41;.getDeclaringClass&#40;&#41;&#41;&#41; &#123;
                return m.getMethod&#40;&#41;.invoke&#40;this, m.getArguments&#40;&#41;&#41;;
            &#125; else &#123;
                return m.proceed&#40;&#41;;
            &#125;
        &#125;
    
        private Date lastModifiedDate;
    
        public Date getLastModifiedDate&#40;&#41; &#123;
            return lastModifiedDate;
        &#125;
    
        public void setLastModifiedDate&#40;Date lastModifiedDate&#41; &#123;
            this.lastModifiedDate = lastModifiedDate;
        &#125;
    &#125;
    Code:
    public interface Auditable &#123;
        void setLastModifiedDate&#40;Date date&#41;;
    
        Date getLastModifiedDate&#40;&#41;;
    &#125;
    Code:
    public class Course &#123;
        private String id;
        private String name;
    
        public String getId&#40;&#41; &#123;
            return id;
        &#125;
    
        public void setId&#40;String id&#41; &#123;
            this.id = id;
        &#125;
    
        public String getName&#40;&#41; &#123;
            return name;
        &#125;
    
        public void setName&#40;String name&#41; &#123;
            this.name = name;
        &#125;
    
        public java.util.Set getStudents&#40;&#41; &#123;
            return null;
    
        &#125;
    
        public java.util.Set getPrerequisites&#40;&#41; &#123;
            return null;
        &#125;
    &#125;

  • #2
    Surely you need to cast it to Auditable?

    Comment


    • #3
      Originally posted by yatesco
      Surely you need to cast it to Auditable?
      All I want is just to extend Course with Auditable Interface functionality .

      Comment


      • #4
        Originally posted by maestro
        Originally posted by yatesco
        Surely you need to cast it to Auditable?
        All I want is just to extend Course with Auditable Interface functionality .
        I think in your case you would need to specify targetName rather than reference to the bean. Since introductions are statetfull you really do not want each proxy referencing the same instance of the target, and I guess spring is smart enough to actually catch this :-)

        Comment


        • #5
          Originally posted by bpolka
          Originally posted by maestro
          Originally posted by yatesco
          Surely you need to cast it to Auditable?
          All I want is just to extend Course with Auditable Interface functionality .
          I think in your case you would need to specify targetName rather than reference to the bean. Since introductions are statetfull you really do not want each proxy referencing the same instance of the target, and I guess spring is smart enough to actually catch this :-)
          Could You point me where should I rewrite code ? I can't mind how should it look like.

          Comment

          Working...
          X