File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
spring-boot-project/spring-boot-docs/src
docs/antora/modules/how-to/pages
java/org/springframework/boot/docs/howto/dataaccess/filterscannedentitydefinitions
kotlin/org/springframework/boot/docs/howto/dataaccess/filterscannedentitydefinitions Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,17 @@ include-code::MyApplication[]
177
177
178
178
179
179
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
+
180
191
[[howto.data-access.jpa-properties]]
181
192
== Configure JPA Properties
182
193
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments