Under what circumstances. Can it be defined in code. You can use Spring 3.0 Expression Language, or the PropertyPlaceholderConfigurer.
SPel would be #{} where inside the curly braces is some method call or other evaluation that determines what you want to set your ref to.
PropertyPlaceholderConfigurer would be ${variable_name} using a .properties file to store the ref value.
There are always the Factory
pattern you can use to create the ref that you need also.
There are many solutions, but without knowing how you determine the ref value you want we can't help more.
Thanks
Mark