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
37c60b66
Commit
37c60b66
authored
Oct 09, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
0fba98ca
51a1309a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
87 deletions
+74
-87
SpringDataWebAutoConfigurationTests.java
...nfigure/data/web/SpringDataWebAutoConfigurationTests.java
+66
-87
howto.adoc
...oot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+8
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java
View file @
37c60b66
...
@@ -16,19 +16,14 @@
...
@@ -16,19 +16,14 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
web
;
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
web
;
import
java.util.Map
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.web.PageableHandlerMethodArgumentResolver
;
import
org.springframework.data.web.PageableHandlerMethodArgumentResolver
;
import
org.springframework.data.web.SortHandlerMethodArgumentResolver
;
import
org.springframework.data.web.SortHandlerMethodArgumentResolver
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -41,104 +36,88 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -41,104 +36,88 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
SpringDataWebAutoConfigurationTests
{
public
class
SpringDataWebAutoConfigurationTests
{
private
AnnotationConfigWebApplicationContext
context
;
private
final
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withConfiguration
(
@After
AutoConfigurations
.
of
(
SpringDataWebAutoConfiguration
.
class
));
public
void
after
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
@Test
public
void
webSupportIsAutoConfiguredInWebApplicationContexts
()
{
public
void
webSupportIsAutoConfiguredInWebApplicationContexts
()
{
load
();
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
)
this
.
context
.
setServletContext
(
new
MockServletContext
());
.
hasSingleBean
(
PageableHandlerMethodArgumentResolver
.
class
));
Map
<
String
,
PageableHandlerMethodArgumentResolver
>
beans
=
this
.
context
.
getBeansOfType
(
PageableHandlerMethodArgumentResolver
.
class
);
assertThat
(
beans
).
hasSize
(
1
);
}
}
@Test
@Test
public
void
autoConfigurationBacksOffInNonWebApplicationContexts
()
{
public
void
autoConfigurationBacksOffInNonWebApplicationContexts
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
new
ApplicationContextRunner
()
ctx
.
register
(
SpringDataWebAutoConfiguration
.
class
);
.
withConfiguration
(
try
{
AutoConfigurations
.
of
(
SpringDataWebAutoConfiguration
.
class
))
ctx
.
refresh
();
.
run
((
context
)
->
assertThat
(
context
)
Map
<
String
,
PageableHandlerMethodArgumentResolver
>
beans
=
ctx
.
doesNotHaveBean
(
PageableHandlerMethodArgumentResolver
.
class
));
.
getBeansOfType
(
PageableHandlerMethodArgumentResolver
.
class
);
assertThat
(
beans
).
isEmpty
();
}
finally
{
ctx
.
close
();
}
}
}
@Test
@Test
public
void
customizePageable
()
{
public
void
customizePageable
()
{
load
(
"spring.data.web.pageable.page-parameter=p"
,
this
.
contextRunner
"spring.data.web.pageable.size-parameter=s"
,
.
withPropertyValues
(
"spring.data.web.pageable.page-parameter=p"
,
"spring.data.web.pageable.default-page-size=10"
,
"spring.data.web.pageable.size-parameter=s"
,
"spring.data.web.pageable.prefix=abc"
,
"spring.data.web.pageable.default-page-size=10"
,
"spring.data.web.pageable.qualifier-delimiter=__"
,
"spring.data.web.pageable.prefix=abc"
,
"spring.data.web.pageable.max-page-size=100"
,
"spring.data.web.pageable.qualifier-delimiter=__"
,
"spring.data.web.pageable.one-indexed-parameters=true"
);
"spring.data.web.pageable.max-page-size=100"
,
PageableHandlerMethodArgumentResolver
argumentResolver
=
this
.
context
"spring.data.web.pageable.one-indexed-parameters=true"
)
.
getBean
(
PageableHandlerMethodArgumentResolver
.
class
);
.
run
((
context
)
->
{
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"pageParameterName"
))
PageableHandlerMethodArgumentResolver
argumentResolver
=
context
.
isEqualTo
(
"p"
);
.
getBean
(
PageableHandlerMethodArgumentResolver
.
class
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"sizeParameterName"
))
assertThat
(
argumentResolver
)
.
isEqualTo
(
"s"
);
.
hasFieldOrPropertyWithValue
(
"pageParameterName"
,
"p"
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"oneIndexedParameters"
))
assertThat
(
argumentResolver
)
.
isEqualTo
(
true
);
.
hasFieldOrPropertyWithValue
(
"sizeParameterName"
,
"s"
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"prefix"
))
assertThat
(
argumentResolver
)
.
isEqualTo
(
"abc"
);
.
hasFieldOrPropertyWithValue
(
"oneIndexedParameters"
,
true
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"qualifierDelimiter"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"prefix"
,
.
isEqualTo
(
"__"
);
"abc"
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"fallbackPageable"
))
assertThat
(
argumentResolver
)
.
isEqualTo
(
PageRequest
.
of
(
0
,
10
));
.
hasFieldOrPropertyWithValue
(
"qualifierDelimiter"
,
"__"
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"maxPageSize"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
.
isEqualTo
(
100
);
"fallbackPageable"
,
PageRequest
.
of
(
0
,
10
));
assertThat
(
argumentResolver
)
.
hasFieldOrPropertyWithValue
(
"maxPageSize"
,
100
);
});
}
}
@Test
@Test
public
void
defaultPageable
()
{
public
void
defaultPageable
()
{
load
();
this
.
contextRunner
.
run
((
context
)
->
{
PageableHandlerMethodArgumentResolver
argumentResolver
=
this
.
context
SpringDataWebProperties
.
Pageable
properties
=
new
SpringDataWebProperties
()
.
getBean
(
PageableHandlerMethodArgumentResolver
.
class
);
.
getPageable
();
SpringDataWebProperties
.
Pageable
properties
=
new
SpringDataWebProperties
()
PageableHandlerMethodArgumentResolver
argumentResolver
=
context
.
getPageable
();
.
getBean
(
PageableHandlerMethodArgumentResolver
.
class
);
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"pageParameterName"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"pageParameterName"
,
.
isEqualTo
(
properties
.
getPageParameter
());
properties
.
getPageParameter
());
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"sizeParameterName"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"sizeParameterName"
,
.
isEqualTo
(
properties
.
getSizeParameter
());
properties
.
getSizeParameter
());
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"oneIndexedParameters"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
.
isEqualTo
(
properties
.
isOneIndexedParameters
());
"oneIndexedParameters"
,
properties
.
isOneIndexedParameters
());
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"prefix"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"prefix"
,
.
isEqualTo
(
properties
.
getPrefix
());
properties
.
getPrefix
());
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"qualifierDelimiter"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"qualifierDelimiter"
,
.
isEqualTo
(
properties
.
getQualifierDelimiter
());
properties
.
getQualifierDelimiter
());
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"fallbackPageable"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"fallbackPageable"
,
.
isEqualTo
(
PageRequest
.
of
(
0
,
properties
.
getDefaultPageSize
()));
PageRequest
.
of
(
0
,
properties
.
getDefaultPageSize
()));
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"maxPageSize"
))
assertThat
(
argumentResolver
).
hasFieldOrPropertyWithValue
(
"maxPageSize"
,
.
isEqualTo
(
properties
.
getMaxPageSize
());
properties
.
getMaxPageSize
());
});
}
}
@Test
@Test
public
void
customizeSort
()
{
public
void
customizeSort
()
{
load
(
"spring.data.web.sort.sort-parameter=s"
);
this
.
contextRunner
.
withPropertyValues
(
"spring.data.web.sort.sort-parameter=s"
)
SortHandlerMethodArgumentResolver
argumentResolver
=
this
.
context
.
run
((
context
)
->
{
.
getBean
(
SortHandlerMethodArgumentResolver
.
class
);
SortHandlerMethodArgumentResolver
argumentResolver
=
context
assertThat
(
ReflectionTestUtils
.
getField
(
argumentResolver
,
"sortParameter"
))
.
getBean
(
SortHandlerMethodArgumentResolver
.
class
);
.
isEqualTo
(
"s"
);
assertThat
(
argumentResolver
)
}
.
hasFieldOrPropertyWithValue
(
"sortParameter"
,
"s"
);
});
private
void
load
(
String
...
environment
)
{
AnnotationConfigWebApplicationContext
ctx
=
new
AnnotationConfigWebApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
ctx
);
ctx
.
register
(
SpringDataWebAutoConfiguration
.
class
);
ctx
.
refresh
();
this
.
context
=
ctx
;
}
}
}
}
spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
37c60b66
...
@@ -2140,6 +2140,14 @@ the annotations and flags accordingly.
...
@@ -2140,6 +2140,14 @@ the annotations and flags accordingly.
[[howto-use-customize-spring-datas-web-support]]
=== Customize Spring Data's Web Support
Spring Data provides web support that simplifies the use of Spring Data repositories in a
web application. Spring Boot provides properties in the `spring.data.web` namespace
for customizing its configuration. Note that if you are using Spring Data REST, you must
use the properties in the `spring.data.rest` namespace instead.
[[howto-use-exposing-spring-data-repositories-rest-endpoint]]
[[howto-use-exposing-spring-data-repositories-rest-endpoint]]
=== Expose Spring Data Repositories as REST Endpoint
=== Expose Spring Data Repositories as REST Endpoint
Spring Data REST can expose the `Repository` implementations as REST endpoints for you,
Spring Data REST can expose the `Repository` implementations as REST endpoints for you,
...
...
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