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
0bc5c2ba
Commit
0bc5c2ba
authored
Apr 09, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that containers' static resource handling not MVC's is used
Closes gh-25949
parent
709db558
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
30 deletions
+47
-30
build.gradle
...t-integration-tests/spring-boot-server-tests/build.gradle
+0
-2
ExampleAutoConfiguration.java
...rc/test/java/com/autoconfig/ExampleAutoConfiguration.java
+28
-11
ResourceHandlingApplication.java
...rc/test/java/com/example/ResourceHandlingApplication.java
+10
-2
ApplicationBuilder.java
...ngframework/boot/context/embedded/ApplicationBuilder.java
+1
-3
EmbeddedServletContainerJarPackagingIntegrationTests.java
...EmbeddedServletContainerJarPackagingIntegrationTests.java
+2
-2
EmbeddedServletContainerWarPackagingIntegrationTests.java
...EmbeddedServletContainerWarPackagingIntegrationTests.java
+4
-3
application.yml
...ring-boot-server-tests/src/test/resources/application.yml
+0
-1
pom-template.xml
...ing-boot-server-tests/src/test/resources/pom-template.xml
+2
-6
No files found.
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle
View file @
0bc5c2ba
...
@@ -11,7 +11,6 @@ configurations {
...
@@ -11,7 +11,6 @@ configurations {
dependencies
{
dependencies
{
testImplementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-test"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-test"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-actuator-autoconfigure"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-test-support"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-tools:spring-boot-test-support"
))
testImplementation
(
"com.samskivert:jmustache"
)
testImplementation
(
"com.samskivert:jmustache"
)
testImplementation
(
"jakarta.servlet:jakarta.servlet-api"
)
testImplementation
(
"jakarta.servlet:jakarta.servlet-api"
)
...
@@ -26,7 +25,6 @@ dependencies {
...
@@ -26,7 +25,6 @@ dependencies {
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-dependencies"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-dependencies"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-json"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-json"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-parent"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-parent"
,
configuration:
"mavenRepository"
))
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java
View file @
0bc5c2ba
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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,27 +16,44 @@
...
@@ -16,27 +16,44 @@
package
com
.
autoconfig
;
package
com
.
autoconfig
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
java.io.IOException
;
import
org.springframework.boot.actuate.endpoint.annotation.ReadOperation
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWarDeployment
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWarDeployment
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.MediaType
;
@ConditionalOnWarDeployment
@Configuration
@Configuration
public
class
ExampleAutoConfiguration
{
public
class
ExampleAutoConfiguration
{
@Bean
@Bean
public
TestEndpoint
testEndpoint
()
{
@ConditionalOnWarDeployment
return
new
TestEndpoint
();
public
ServletRegistrationBean
<
TestServlet
>
onWarTestServlet
()
{
ServletRegistrationBean
<
TestServlet
>
registration
=
new
ServletRegistrationBean
<>(
new
TestServlet
());
registration
.
addUrlMappings
(
"/conditionalOnWar"
);
return
registration
;
}
@Bean
public
ServletRegistrationBean
<
TestServlet
>
testServlet
()
{
ServletRegistrationBean
<
TestServlet
>
registration
=
new
ServletRegistrationBean
<>(
new
TestServlet
());
registration
.
addUrlMappings
(
"/always"
);
return
registration
;
}
}
@Endpoint
(
id
=
"war"
)
static
class
TestServlet
extends
HttpServlet
{
static
class
TestEndpoint
{
@ReadOperation
@Override
String
hello
()
{
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
return
"{\"hello\":\"world\"}"
;
resp
.
setContentType
(
MediaType
.
APPLICATION_JSON_VALUE
);
resp
.
getWriter
().
println
(
"{\"hello\":\"world\"}"
);
resp
.
flushBuffer
();
}
}
}
}
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java
View file @
0bc5c2ba
...
@@ -56,9 +56,17 @@ public class ResourceHandlingApplication {
...
@@ -56,9 +56,17 @@ public class ResourceHandlingApplication {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
try
{
Class
.
forName
(
"org.springframework.web.servlet.DispatcherServlet"
);
System
.
err
.
println
(
"Spring MVC must not be present, otherwise its static resource handling "
+
"will be used rather than the embedded containers'"
);
System
.
exit
(
1
);
}
catch
(
Throwable
ex
)
{
new
SpringApplicationBuilder
(
ResourceHandlingApplication
.
class
).
properties
(
"server.port:0"
)
new
SpringApplicationBuilder
(
ResourceHandlingApplication
.
class
).
properties
(
"server.port:0"
)
.
listeners
(
new
WebServerPortFileWriter
(
args
[
0
])).
run
(
args
);
.
listeners
(
new
WebServerPortFileWriter
(
args
[
0
])).
run
(
args
);
}
}
}
private
static
final
class
GetResourcePathsServlet
extends
HttpServlet
{
private
static
final
class
GetResourcePathsServlet
extends
HttpServlet
{
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java
View file @
0bc5c2ba
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -161,8 +161,6 @@ class ApplicationBuilder {
...
@@ -161,8 +161,6 @@ class ApplicationBuilder {
metaInf
.
mkdirs
();
metaInf
.
mkdirs
();
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/META-INF/spring.factories"
),
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/META-INF/spring.factories"
),
new
File
(
metaInf
,
"spring.factories"
));
new
File
(
metaInf
,
"spring.factories"
));
FileCopyUtils
.
copy
(
new
File
(
"src/test/resources/application.yml"
),
new
File
(
srcMainResources
,
"application.yml"
));
}
}
private
void
packageApplication
(
File
appDirectory
,
File
settingsXml
)
throws
MavenInvocationException
{
private
void
packageApplication
(
File
appDirectory
,
File
settingsXml
)
throws
MavenInvocationException
{
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java
View file @
0bc5c2ba
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -81,7 +81,7 @@ class EmbeddedServletContainerJarPackagingIntegrationTests {
...
@@ -81,7 +81,7 @@ class EmbeddedServletContainerJarPackagingIntegrationTests {
@TestTemplate
@TestTemplate
void
conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer
(
RestTemplate
rest
)
{
void
conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer
(
RestTemplate
rest
)
{
ResponseEntity
<
String
>
entity
=
rest
.
getForEntity
(
"/
actuator/
war"
,
String
.
class
);
ResponseEntity
<
String
>
entity
=
rest
.
getForEntity
(
"/war"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
}
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java
View file @
0bc5c2ba
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
@@ -104,8 +104,9 @@ class EmbeddedServletContainerWarPackagingIntegrationTests {
...
@@ -104,8 +104,9 @@ class EmbeddedServletContainerWarPackagingIntegrationTests {
@TestTemplate
@TestTemplate
void
conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer
(
RestTemplate
rest
)
{
void
conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer
(
RestTemplate
rest
)
{
ResponseEntity
<
String
>
entity
=
rest
.
getForEntity
(
"/actuator/war"
,
String
.
class
);
assertThat
(
rest
.
getForEntity
(
"/always"
,
String
.
class
).
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
rest
.
getForEntity
(
"/conditionalOnWar"
,
String
.
class
).
getStatusCode
())
.
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
}
private
List
<
String
>
readLines
(
String
input
)
{
private
List
<
String
>
readLines
(
String
input
)
{
...
...
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/application.yml
deleted
100644 → 0
View file @
709db558
management.endpoints.web.exposure.include
:
'
*'
spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml
View file @
0bc5c2ba
...
@@ -18,11 +18,7 @@
...
@@ -18,11 +18,7 @@
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-json
</artifactId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -30,7 +26,7 @@
...
@@ -30,7 +26,7 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
mvc
</artifactId>
<artifactId>
spring-web
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<groupId>
javax.servlet
</groupId>
...
...
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