AbstractCachingViewResolver caches unresolved view names by default ("cacheUnresolved"=true; SPR-8173)

This commit is contained in:
Juergen Hoeller 2011-11-28 22:46:53 +00:00
parent 1bb6d29be2
commit c2eafdb2fb
1 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,18 +16,11 @@
package org.springframework.web.servlet.view; package org.springframework.web.servlet.view;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -39,6 +32,7 @@ import javax.servlet.jsp.jstl.core.Config;
import javax.servlet.jsp.jstl.fmt.LocalizationContext; import javax.servlet.jsp.jstl.fmt.LocalizationContext;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue; import org.springframework.beans.PropertyValue;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
@ -59,6 +53,8 @@ import org.springframework.web.servlet.i18n.FixedLocaleResolver;
import org.springframework.web.servlet.support.RequestContext; import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.theme.FixedThemeResolver; import org.springframework.web.servlet.theme.FixedThemeResolver;
import static org.junit.Assert.*;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
@ -499,7 +495,7 @@ public class ViewResolverTests {
vr.removeFromCache("example1", Locale.getDefault()); vr.removeFromCache("example1", Locale.getDefault());
cached = vr.resolveViewName("example1", Locale.getDefault()); cached = vr.resolveViewName("example1", Locale.getDefault());
if (view == cached) { if (view == cached) {
// the chance of having the same reference (hashCode) twice if negligable). // the chance of having the same reference (hashCode) twice if negligible).
fail("View wasn't removed from cache"); fail("View wasn't removed from cache");
} }
} }
@ -524,12 +520,16 @@ public class ViewResolverTests {
viewResolver.setCacheUnresolved(true); viewResolver.setCacheUnresolved(true);
viewResolver.resolveViewName("view", Locale.getDefault());
viewResolver.resolveViewName("view", Locale.getDefault());
viewResolver.resolveViewName("view", Locale.getDefault());
viewResolver.resolveViewName("view", Locale.getDefault()); viewResolver.resolveViewName("view", Locale.getDefault());
viewResolver.resolveViewName("view", Locale.getDefault()); viewResolver.resolveViewName("view", Locale.getDefault());
assertEquals(2, count.intValue()); assertEquals(3, count.intValue());
} }
public static class TestView extends InternalResourceView { public static class TestView extends InternalResourceView {
public void setLocation(Resource location) { public void setLocation(Resource location) {