Initialize Abstract Property in Spring Framework

543 views Asked by At

I am wondering how to initialize a variable in abstract class in Spring Framework. I cannot change the constructor which is already present. I have referred to http://forum.spring.io/forum/spring-projects/container/47496-dependency-inject-abstract-class-property but the property has null value.

I have used abtract=true in my xml file.

My Abstract Class:

    package com.hi;
    public abstract class Xyz implements Serializable{
            private String path;
            public String getPath(){return path;}
            public void setPath(String path){this.path = path;}
            private void init(){
                //path will be used to get the file from the location
            }
            public Serializable getExpr(){
                 init();
            }
    }

My Inherited Class:

public class Abc extends Xyz implements Serializable{
   private Abc(String a){
       super(a,TYPE.data);
   }
   public static Abc of(){
      return new Abc(a);
   }
}

My xml file:

<bean id="xyz"
          class="com.hi.Xyz"
          abstract="true">
        <property name="path" value="${PATH}" />
</bean>

The inherited class does not have to get the file. So the abstract class can have the path directly injected and use the path.

0

There are 0 answers