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
b1d8cc55
Commit
b1d8cc55
authored
Jun 21, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Fix JSP availability check when not running as a packaged war"
Closes gh-12859
parent
82465cf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
JspTemplateAvailabilityProvider.java
...ot/autoconfigure/web/JspTemplateAvailabilityProvider.java
+7
-3
error.jsp
...boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp
+6
-0
SampleWebJspApplicationTests.java
...rc/test/java/sample/jsp/SampleWebJspApplicationTests.java
+19
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java
View file @
b1d8cc55
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
java.io.File
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
...
@@ -38,8 +40,10 @@ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProv
...
@@ -38,8 +40,10 @@ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProv
ClassLoader
classLoader
,
ResourceLoader
resourceLoader
)
{
ClassLoader
classLoader
,
ResourceLoader
resourceLoader
)
{
if
(
ClassUtils
.
isPresent
(
"org.apache.jasper.compiler.JspConfig"
,
classLoader
))
{
if
(
ClassUtils
.
isPresent
(
"org.apache.jasper.compiler.JspConfig"
,
classLoader
))
{
String
resourceName
=
getResourceName
(
view
,
environment
);
String
resourceName
=
getResourceName
(
view
,
environment
);
return
resourceLoader
.
getResource
(
resourceName
).
exists
()
||
if
(
resourceLoader
.
getResource
(
resourceName
).
exists
())
{
resourceLoader
.
getResource
(
"file:./src/main/webapp"
+
resourceName
).
exists
();
return
true
;
}
return
new
File
(
"src/main/webapp"
,
resourceName
).
exists
();
}
}
return
false
;
return
false
;
}
}
...
...
spring-boot-samples/spring-boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp
0 → 100644
View file @
b1d8cc55
<!DOCTYPE html>
<html
lang=
"en"
>
<body>
Something went wrong: ${status} ${error}
</body>
</html>
\ No newline at end of file
spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java
View file @
b1d8cc55
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
sample
.
jsp
;
package
sample
.
jsp
;
import
java.net.URI
;
import
java.util.Arrays
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -23,7 +26,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -23,7 +26,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
...
@@ -50,4 +57,15 @@ public class SampleWebJspApplicationTests {
...
@@ -50,4 +57,15 @@ public class SampleWebJspApplicationTests {
assertThat
(
entity
.
getBody
()).
contains
(
"/resources/text.txt"
);
assertThat
(
entity
.
getBody
()).
contains
(
"/resources/text.txt"
);
}
}
@Test
public
void
customErrorPage
()
throws
Exception
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setAccept
(
Arrays
.
asList
(
MediaType
.
TEXT_HTML
));
RequestEntity
<
Void
>
request
=
new
RequestEntity
<>(
headers
,
HttpMethod
.
GET
,
URI
.
create
(
"/foo"
));
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
exchange
(
request
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getBody
()).
contains
(
"Something went wrong"
);
}
}
}
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