diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java index b92945d7df..1245f75a16 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java @@ -153,7 +153,7 @@ class BeanDefinitionMethodGenerator { nonGeneratedParent = nonGeneratedParent.getParent(); } if (nonGeneratedParent != null) { - return StringUtils.uncapitalize(getSimpleBeanName(nonGeneratedParent.getBeanName()) + "InnerBean"); + return getSimpleBeanName(nonGeneratedParent.getBeanName()) + "InnerBean"; } return "innerBean"; } @@ -163,7 +163,7 @@ class BeanDefinitionMethodGenerator { beanName = (lastDot != -1) ? beanName.substring(lastDot + 1) : beanName; int lastDollar = beanName.lastIndexOf('$'); beanName = (lastDollar != -1) ? beanName.substring(lastDollar + 1) : beanName; - return beanName; + return StringUtils.uncapitalize(beanName); } } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java index 3d8e626a13..8ddedb2c09 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java @@ -69,13 +69,25 @@ public class GeneratedMethods { */ public GeneratedMethod add(String suggestedName, Consumer method) { Assert.notNull(suggestedName, "'suggestedName' must not be null"); + return add(new String[] { suggestedName }, method); + } + + /** + * Add a new {@link GeneratedMethod}. + * @param suggestedNameParts the suggested name parts for the method + * @param method a {@link Consumer} used to build method + * @return the newly added {@link GeneratedMethod} + */ + public GeneratedMethod add(String[] suggestedNameParts, Consumer method) { + Assert.notNull(suggestedNameParts, "'suggestedNameParts' must not be null"); Assert.notNull(method, "'method' must not be null"); - String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedName)); + String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedNameParts)); GeneratedMethod generatedMethod = new GeneratedMethod(generatedName, method); this.generatedMethods.add(generatedMethod); return generatedMethod; } + public GeneratedMethods withPrefix(String prefix) { Assert.notNull(prefix, "'prefix' must not be null"); return new GeneratedMethods(this.methodNameGenerator, this.prefix.and(prefix), this.generatedMethods); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index 0f3aae4dc4..4707859660 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -825,8 +825,8 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar EntityManagerFactoryUtils.class, ListableBeanFactory.class, REGISTERED_BEAN_PARAMETER, unitName); } - String methodName = "get" + StringUtils.capitalize(unitName) + "EntityManager"; - GeneratedMethod generatedMethod = generatedMethods.add(methodName, method -> + String[] methodNameParts = { "get" , unitName, "EntityManager" }; + GeneratedMethod generatedMethod = generatedMethods.add(methodNameParts, method -> generateGetEntityManagerMethod(method, injectedElement)); return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER); }