Skip to content

Commit 11447c1

Browse files
schaudermp911de
authored andcommitted
Stop using deprecated constructor of AuditHandler for XML configuration.
Introduces PersistentEntitiesFactoryBean. Closes #2467
1 parent 26dc988 commit 11447c1

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

Diff for: src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import org.springframework.data.auditing.AuditingHandler;
2929
import org.springframework.data.config.ParsingUtils;
3030
import org.springframework.data.mapping.context.MappingContext;
31+
import org.springframework.data.repository.config.PersistentEntitiesFactoryBean;
3132
import org.springframework.lang.NonNull;
3233
import org.springframework.util.Assert;
3334
import org.springframework.util.StringUtils;
34-
3535
import org.w3c.dom.Element;
3636

3737
/**
@@ -95,7 +95,8 @@ protected boolean shouldGenerateId() {
9595
@Override
9696
protected void doParse(Element element, BeanDefinitionBuilder builder) {
9797

98-
builder.addConstructorArgReference(mappingContextBeanName);
98+
final BeanDefinitionBuilder persistentEntities = rootBeanDefinition(PersistentEntitiesFactoryBean.class);
99+
builder.addConstructorArgValue(persistentEntities.getBeanDefinition());
99100

100101
String auditorAwareRef = element.getAttribute(AUDITOR_AWARE_REF);
101102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2021 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+
package org.springframework.data.repository.config;
17+
18+
import org.springframework.beans.factory.FactoryBean;
19+
import org.springframework.data.mapping.context.MappingContext;
20+
import org.springframework.data.mapping.context.PersistentEntities;
21+
22+
/**
23+
* Factory been to create {@link PersistentEntities} from a {@link MappingContext}.
24+
*
25+
* @author Jens Schauder
26+
* @since 3.0
27+
*/
28+
public class PersistentEntitiesFactoryBean implements FactoryBean<PersistentEntities> {
29+
30+
private final MappingContext context;
31+
32+
/**
33+
* Creates a new {@link PersistentEntitiesFactoryBean} for the given {@link MappingContext}.
34+
*
35+
* @param context must not be {@literal null}.
36+
*/
37+
public PersistentEntitiesFactoryBean(MappingContext context) {
38+
this.context = context;
39+
}
40+
41+
/*
42+
* (non-Javadoc)
43+
* @see org.springframework.beans.factory.FactoryBean#getObject()
44+
*/
45+
@Override
46+
public PersistentEntities getObject() {
47+
return PersistentEntities.of(context);
48+
}
49+
50+
/*
51+
* (non-Javadoc)
52+
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
53+
*/
54+
@Override
55+
public Class<?> getObjectType() {
56+
return PersistentEntities.class;
57+
}
58+
}

0 commit comments

Comments
 (0)