PDA

View Full Version : PropertiesBeanDefinitionReader bug won't allow certain views


asmith
Sep 30th, 2004, 01:04 AM
If you are using a ResourceBundleViewResolver and you want to use view names that contain a "." (that's a dot), you are out of luck.

The offending code is located in org.springframework.beans.factory.support.Properti esBeanDefinitionReader starting at line 253:


public int registerBeanDefinitions(Map map, String prefix, String resourceDescription) throws BeansException {
if (prefix == null) {
prefix = "";
}
int beanCount = 0;

Set keys = map.keySet();
Iterator itr = keys.iterator();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.startsWith(prefix)) {
// Key is of form prefix<name>.property
String nameAndProperty = key.substring(prefix.length());
int sepIndx = nameAndProperty.indexOf(SEPARATOR);
if (sepIndx != -1) {
String beanName = nameAndProperty.substring(0, sepIndx);


The problem is your view doesn't start with a prefix but the tokenizer steps in and chops the view name off at the first "." on line 266. It could be fixed by making sure prefix has a positive length on line 263.

Until then -- no dots in your views defined by ResourceBundles.

-a.

Juergen Hoeller
Oct 2nd, 2004, 06:59 AM
Good point! Actually, the separator is between bean name and property name: The only fix requires is to use "lastIndexOf" rather than "indexOf" (a property name is not allowed to contain a dot). I've just fixed this, and also added corresponding tests.

Juergen