After no help from SO ..did some some self struggle and found following solution , if it could help somebody:
I realized that Spring Context was getting initialized even before the static block.
So to get the context indirectly , created a class to get the context.
public class SpringBean {
@Autowired
private ApplicationContext applicationContext;
private static SpringBean bean = new SpringBean();
public static SpringBean getInstance() {
return bean;
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public Object getBean(String beanName) {
if (applicationContext == null) {
throw new IllegalStateException("No context initialised.");
}
return applicationContext.getBean(beanName);
}
}
Note: Same class could be created implimenting ApplicationContextAware interface by SpringBean.
declare this in spring config file as :
<context:annotation-config/>
<bean class="com.db.icestation.server.pd.common.SpringBean"
factory-method="getInstance"/>
Also created a String SWITCH variable 'appContext' in spring config , this is the varibale which was my objective to inject in AppProperty class.
<bean id="appContext" class="java.lang.String">
<constructor-arg value="Atlast..Injecting this string in a static block..."/>
</bean>
Finally.... get this value in your main class "AppProperty" above .....
public static String appContext; // My problem .. see question above...now resolved
static{
appContext = SpringBean.getInstance().getBean("appContext").toString();
init();
}