Skip to content

Commit d945443

Browse files
snicollscottfrederick
authored andcommitted
Add How-To documentation for ManagedClassNameFilter
This commit documents the support of ManagedClassNameFilter that was added in gh-39813. See gh-40617
1 parent 208efae commit d945443

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/data-access.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ include-code::MyApplication[]
177177

178178

179179

180+
[[howto.data-access.filter-scanned-entity-definitions]]
181+
== Filter scanned @Entity definitions
182+
183+
It is possible to exclude some `@Entity` definitions using a `ManagedClassNameFilter` bean.
184+
This can be useful in tests when only a sub-set of the available entities should be considered.
185+
In the following example, only entities from the `com.example.app.customer` package are included:
186+
187+
include-code::MyEntityScanConfiguration[]
188+
189+
190+
180191
[[howto.data-access.jpa-properties]]
181192
== Configure JPA Properties
182193

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.howto.dataaccess.filterscannedentitydefinitions;
18+
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.orm.jpa.persistenceunit.ManagedClassNameFilter;
22+
23+
@Configuration(proxyBeanMethods = false)
24+
public class MyEntityScanConfiguration {
25+
26+
@Bean
27+
public ManagedClassNameFilter entityScanFilter() {
28+
return (className) -> className.startsWith("com.example.app.customer");
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.howto.dataaccess.filterscannedentitydefinitions
18+
19+
import org.springframework.context.annotation.Bean
20+
import org.springframework.context.annotation.Configuration
21+
import org.springframework.orm.jpa.persistenceunit.ManagedClassNameFilter
22+
23+
@Configuration(proxyBeanMethods = false)
24+
class MyEntityScanConfiguration {
25+
26+
@Bean
27+
fun entityScanFilter() : ManagedClassNameFilter {
28+
return ManagedClassNameFilter { className ->
29+
className.startsWith("com.example.app.customer")
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)