Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c3201a1e
Commit
c3201a1e
authored
May 18, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Cache resolved error template view names"
See gh-5989
parent
6698af08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
61 deletions
+1
-61
DefaultErrorViewResolver.java
...work/boot/autoconfigure/web/DefaultErrorViewResolver.java
+1
-45
DefaultErrorViewResolverTests.java
...boot/autoconfigure/web/DefaultErrorViewResolverTests.java
+0
-16
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewResolver.java
View file @
c3201a1e
...
@@ -18,10 +18,8 @@ package org.springframework.boot.autoconfigure.web;
...
@@ -18,10 +18,8 @@ package org.springframework.boot.autoconfigure.web;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -68,10 +66,6 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
...
@@ -68,10 +66,6 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
SERIES_VIEWS
=
Collections
.
unmodifiableMap
(
views
);
SERIES_VIEWS
=
Collections
.
unmodifiableMap
(
views
);
}
}
private
static
final
int
CACHE_LIMIT
=
1024
;
private
static
final
Object
UNRESOLVED
=
new
Object
();
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
private
final
ResourceProperties
resourceProperties
;
private
final
ResourceProperties
resourceProperties
;
...
@@ -80,30 +74,6 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
...
@@ -80,30 +74,6 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
private
int
order
=
Ordered
.
LOWEST_PRECEDENCE
;
private
int
order
=
Ordered
.
LOWEST_PRECEDENCE
;
/**
* resolved template views, returning already cached instances without a global lock.
*/
private
final
Map
<
Object
,
Object
>
resolved
=
new
ConcurrentHashMap
<
Object
,
Object
>(
CACHE_LIMIT
);
/**
* Map from view name resolve template view, synchronized when accessed.
*/
@SuppressWarnings
(
"serial"
)
private
final
Map
<
Object
,
Object
>
cache
=
new
LinkedHashMap
<
Object
,
Object
>(
CACHE_LIMIT
,
0.75f
,
true
)
{
@Override
protected
boolean
removeEldestEntry
(
Map
.
Entry
<
Object
,
Object
>
eldest
)
{
if
(
size
()
>
CACHE_LIMIT
)
{
DefaultErrorViewResolver
.
this
.
resolved
.
remove
(
eldest
.
getKey
());
return
true
;
}
return
false
;
}
};
/**
/**
* Create a new {@link DefaultErrorViewResolver} instance.
* Create a new {@link DefaultErrorViewResolver} instance.
* @param applicationContext the source application context
* @param applicationContext the source application context
...
@@ -150,25 +120,11 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
...
@@ -150,25 +120,11 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
}
}
private
ModelAndView
resolveTemplate
(
String
viewName
,
Map
<
String
,
Object
>
model
)
{
private
ModelAndView
resolveTemplate
(
String
viewName
,
Map
<
String
,
Object
>
model
)
{
Object
resolved
=
this
.
resolved
.
get
(
viewName
);
if
(
resolved
==
null
)
{
synchronized
(
this
.
cache
)
{
resolved
=
resolveTemplateViewName
(
viewName
);
resolved
=
(
resolved
==
null
?
UNRESOLVED
:
resolved
);
this
.
resolved
.
put
(
viewName
,
resolved
);
this
.
cache
.
put
(
viewName
,
resolved
);
}
}
return
(
resolved
==
UNRESOLVED
?
null
:
new
ModelAndView
((
String
)
resolved
,
model
));
}
private
String
resolveTemplateViewName
(
String
viewName
)
{
for
(
TemplateAvailabilityProvider
templateAvailabilityProvider
:
this
.
templateAvailabilityProviders
)
{
for
(
TemplateAvailabilityProvider
templateAvailabilityProvider
:
this
.
templateAvailabilityProviders
)
{
if
(
templateAvailabilityProvider
.
isTemplateAvailable
(
"error/"
+
viewName
,
if
(
templateAvailabilityProvider
.
isTemplateAvailable
(
"error/"
+
viewName
,
this
.
applicationContext
.
getEnvironment
(),
this
.
applicationContext
.
getEnvironment
(),
this
.
applicationContext
.
getClassLoader
(),
this
.
applicationContext
))
{
this
.
applicationContext
.
getClassLoader
(),
this
.
applicationContext
))
{
return
"error/"
+
viewName
;
return
new
ModelAndView
(
"error/"
+
viewName
,
model
)
;
}
}
}
}
return
null
;
return
null
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewResolverTests.java
View file @
c3201a1e
...
@@ -47,7 +47,6 @@ import static org.mockito.BDDMockito.given;
...
@@ -47,7 +47,6 @@ import static org.mockito.BDDMockito.given;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
...
@@ -199,21 +198,6 @@ public class DefaultErrorViewResolverTests {
...
@@ -199,21 +198,6 @@ public class DefaultErrorViewResolverTests {
assertThat
(
response
.
getContentType
()).
isEqualTo
(
MediaType
.
TEXT_HTML_VALUE
);
assertThat
(
response
.
getContentType
()).
isEqualTo
(
MediaType
.
TEXT_HTML_VALUE
);
}
}
@Test
public
void
resolveShouldCacheTemplate
()
throws
Exception
{
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/4xx"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
true
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
NOT_FOUND
,
this
.
model
);
assertThat
(
resolved
.
getViewName
()).
isEqualTo
(
"error/4xx"
);
}
verify
(
this
.
templateAvailabilityProvider
,
times
(
1
)).
isTemplateAvailable
(
eq
(
"error/4xx"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
));
}
@Test
@Test
public
void
orderShouldBeLowest
()
throws
Exception
{
public
void
orderShouldBeLowest
()
throws
Exception
{
assertThat
(
this
.
resolver
.
getOrder
()).
isEqualTo
(
Ordered
.
LOWEST_PRECEDENCE
);
assertThat
(
this
.
resolver
.
getOrder
()).
isEqualTo
(
Ordered
.
LOWEST_PRECEDENCE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment