forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Kotlin BeanPostProcessor beans
This commit adds support for Kotlin BeanPostProcessor beans which should be defined in a companion object and annotated with `@JvmStatic`. Closes spring-projectsgh-32946
- Loading branch information
Showing
9 changed files
with
190 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...k/docs/core/validation/validationbeanvalidationspringmethod/ApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.docs.core.validation.validationbeanvalidationspringmethod; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; | ||
|
||
// tag::snippet[] | ||
@Configuration | ||
public class ApplicationConfiguration { | ||
|
||
@Bean | ||
public static MethodValidationPostProcessor validationPostProcessor() { | ||
return new MethodValidationPostProcessor(); | ||
} | ||
} | ||
// end::snippet[] |
34 changes: 34 additions & 0 deletions
34
...e/validation/validationbeanvalidationspringmethodexceptions/ApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.docs.core.validation.validationbeanvalidationspringmethodexceptions; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; | ||
|
||
// tag::snippet[] | ||
@Configuration | ||
public class ApplicationConfiguration { | ||
|
||
@Bean | ||
public static MethodValidationPostProcessor validationPostProcessor() { | ||
MethodValidationPostProcessor processor = new MethodValidationPostProcessor(); | ||
processor.setAdaptConstraintViolations(true); | ||
return processor; | ||
} | ||
} | ||
// end::snippet[] |
34 changes: 34 additions & 0 deletions
34
...ork/docs/core/validation/validationbeanvalidationspringmethod/ApplicationConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.docs.core.validation.validationbeanvalidationspringmethod | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor | ||
|
||
// tag::snippet[] | ||
@Configuration | ||
class ApplicationConfiguration { | ||
|
||
companion object { | ||
|
||
@Bean | ||
@JvmStatic | ||
fun validationPostProcessor() = MethodValidationPostProcessor() | ||
} | ||
} | ||
// end::snippet[] |
36 changes: 36 additions & 0 deletions
36
...ore/validation/validationbeanvalidationspringmethodexceptions/ApplicationConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.docs.core.validation.validationbeanvalidationspringmethodexceptions | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor | ||
|
||
// tag::snippet[] | ||
@Configuration | ||
class ApplicationConfiguration { | ||
|
||
companion object { | ||
|
||
@Bean | ||
@JvmStatic | ||
fun validationPostProcessor() = MethodValidationPostProcessor().apply { | ||
setAdaptConstraintViolations(true) | ||
} | ||
} | ||
} | ||
// end::snippet[] |
11 changes: 11 additions & 0 deletions
11
...rk/docs/core/validation/validationbeanvalidationspringmethod/ApplicationConfiguration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
https://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<!-- tag::snippet[] --> | ||
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/> | ||
<!-- end::snippet[] --> | ||
</beans> |
13 changes: 13 additions & 0 deletions
13
...re/validation/validationbeanvalidationspringmethodexceptions/ApplicationConfiguration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans | ||
https://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<!-- tag::snippet[] --> | ||
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"> | ||
<property name="adaptConstraintViolations" value="true"/> | ||
</bean> | ||
<!-- end::snippet[] --> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters