tags:

views:

25

answers:

1

Is it possible to set a Spring bean sub-property using dot notation? For instance:

<bean name="rememberMe" class="com.mydomain.security.RememberMeManager">
    <property name="cookie.domain" value=".${webRoot}"/>
</bean>

Or do I need to also create an intermediary bean for the Cookie object stored in RememberMeManager.getCookie()?

My objective is to set cookies set by my site to ".mydomain.com" instead of "mydomain.com". I have a properties file with webRoot=mydomain.com in it.

A: 

Spring's PropertyPlaceholder will have no problem with replacing placeholders that are substrings of the property/value, such as ".${webRoot}", and according to the documentation, it will also fallback to the system properties if no property in the properties file is found.

Did you try this? Does it work or not?

matt b
Actually, my question was in regards to `name="cookie.domain"`, and if sub-properties were allowed. I had tried it, but it wasn't giving me the result I wanted, which is why I asked here. But since I asked, I figured out what I did wrong and discovered that it does work.
Tauren
What do you mean by "sub-properties"? Are you asking about what you can do with Spring's placeholders (`${` and `}`), or what the cookie specification allows?
matt b
@matt: sorry to not be clear. By sub-properties, I mean that `domain` is a sub-property of `cookie`. I've only seen top-level bean properties used in spring config files: `name="beanPropertyName"`, but I haven't seen sub-properties used, like: `name="beanPropertyName.subBeanPropertyName"`. Basically, I'm unsure about using a period in the name.
Tauren
I don't think that would work. Rather you would wire up `<property name="cookie">` with a `<bean>` of that class (hopefully it's an easy POJO), and then set the `<property name="domain">` to your desired value.
matt b