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
a0ef61a2
Commit
a0ef61a2
authored
Feb 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable proxy target class for `MethodValidationPostProcessor`
Closes gh-8277
parent
4aecf19c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
1 deletion
+73
-1
ValidationAutoConfiguration.java
...autoconfigure/validation/ValidationAutoConfiguration.java
+1
-0
ValidationAutoConfigurationTests.java
...onfigure/validation/ValidationAutoConfigurationTests.java
+27
-1
ConfigurationPropertiesBindingPostProcessorTests.java
...ies/ConfigurationPropertiesBindingPostProcessorTests.java
+45
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java
View file @
a0ef61a2
...
@@ -53,6 +53,7 @@ public class ValidationAutoConfiguration {
...
@@ -53,6 +53,7 @@ public class ValidationAutoConfiguration {
public
MethodValidationPostProcessor
methodValidationPostProcessor
(
public
MethodValidationPostProcessor
methodValidationPostProcessor
(
Validator
validator
)
{
Validator
validator
)
{
MethodValidationPostProcessor
processor
=
new
MethodValidationPostProcessor
();
MethodValidationPostProcessor
processor
=
new
MethodValidationPostProcessor
();
processor
.
setProxyTargetClass
(
true
);
processor
.
setValidator
(
validator
);
processor
.
setValidator
(
validator
);
return
processor
;
return
processor
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java
View file @
a0ef61a2
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.validation;
...
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.validation;
import
javax.validation.ConstraintViolationException
;
import
javax.validation.ConstraintViolationException
;
import
javax.validation.Validator
;
import
javax.validation.Validator
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.Size
;
import
javax.validation.constraints.Size
;
import
org.junit.After
;
import
org.junit.After
;
...
@@ -63,6 +64,17 @@ public class ValidationAutoConfigurationTests {
...
@@ -63,6 +64,17 @@ public class ValidationAutoConfigurationTests {
service
.
doSomething
(
"KO"
);
service
.
doSomething
(
"KO"
);
}
}
@Test
public
void
validationUsesCglibProxy
()
{
load
(
DefaultAnotherSampleService
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
Validator
.
class
)).
hasSize
(
1
);
DefaultAnotherSampleService
service
=
this
.
context
.
getBean
(
DefaultAnotherSampleService
.
class
);
service
.
doSomething
(
42
);
this
.
thrown
.
expect
(
ConstraintViolationException
.
class
);
service
.
doSomething
(
2
);
}
@Test
@Test
public
void
userDefinedMethodValidationPostProcessorTakesPrecedence
()
{
public
void
userDefinedMethodValidationPostProcessorTakesPrecedence
()
{
load
(
SampleConfiguration
.
class
);
load
(
SampleConfiguration
.
class
);
...
@@ -97,6 +109,20 @@ public class ValidationAutoConfigurationTests {
...
@@ -97,6 +109,20 @@ public class ValidationAutoConfigurationTests {
}
}
interface
AnotherSampleService
{
void
doSomething
(
@Min
(
42
)
Integer
counter
);
}
@Validated
static
class
DefaultAnotherSampleService
implements
AnotherSampleService
{
@Override
public
void
doSomething
(
Integer
counter
)
{
}
}
@Configuration
@Configuration
static
class
SampleConfiguration
{
static
class
SampleConfiguration
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java
View file @
a0ef61a2
...
@@ -142,6 +142,18 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -142,6 +142,18 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
this
.
context
.
refresh
();
this
.
context
.
refresh
();
}
}
@Test
public
void
testSuccessfulValidationWithInterface
()
{
MockEnvironment
env
=
new
MockEnvironment
();
env
.
setProperty
(
"test.foo"
,
"bar"
);
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
register
(
TestConfigurationWithValidationAndInterface
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
ValidatedPropertiesImpl
.
class
).
getFoo
())
.
isEqualTo
(
"bar"
);
}
@Test
@Test
public
void
testInitializersSeeBoundProperties
()
{
public
void
testInitializersSeeBoundProperties
()
{
MockEnvironment
env
=
new
MockEnvironment
();
MockEnvironment
env
=
new
MockEnvironment
();
...
@@ -486,6 +498,39 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -486,6 +498,39 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
}
}
@Configuration
@EnableConfigurationProperties
public
static
class
TestConfigurationWithValidationAndInterface
{
@Bean
public
ValidatedPropertiesImpl
testProperties
()
{
return
new
ValidatedPropertiesImpl
();
}
}
interface
ValidatedProperties
{
String
getFoo
();
}
@ConfigurationProperties
(
"test"
)
@Validated
public
static
class
ValidatedPropertiesImpl
implements
ValidatedProperties
{
@NotNull
private
String
foo
;
@Override
public
String
getFoo
()
{
return
this
.
foo
;
}
public
void
setFoo
(
String
foo
)
{
this
.
foo
=
foo
;
}
}
@Configuration
@Configuration
@EnableConfigurationProperties
@EnableConfigurationProperties
public
static
class
TestConfigurationWithCustomValidator
{
public
static
class
TestConfigurationWithCustomValidator
{
...
...
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