From 551950cdc0997aedb20ecc0589ce0ccd6339677e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 15 May 2014 09:56:11 +0200 Subject: [PATCH] Consistent use of ClassUtils.forName instead of class.getClassLoader().loadClass Issue: SPR-11780 --- .../beans/PropertyEditorRegistrySupport.java | 4 ++-- .../orm/hibernate4/ConfigurableJtaPlatform.java | 11 ++++++----- .../orm/hibernate4/LocalSessionFactoryBuilder.java | 2 +- .../DefaultPersistenceUnitManager.java | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index 42a563f565..939f81a6ac 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -89,7 +89,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { static { try { - zoneIdClass = PropertyEditorRegistrySupport.class.getClassLoader().loadClass("java.time.ZoneId"); + zoneIdClass = ClassUtils.forName("java.time.ZoneId", PropertyEditorRegistrySupport.class.getClassLoader()); } catch (ClassNotFoundException ex) { // Java 8 ZoneId class not available diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/ConfigurableJtaPlatform.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/ConfigurableJtaPlatform.java index ee12509ddd..7942e65a3f 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/ConfigurableJtaPlatform.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/ConfigurableJtaPlatform.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -33,6 +33,7 @@ import org.hibernate.service.Service; import org.springframework.transaction.jta.UserTransactionAdapter; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * Implementation of Hibernate 4's JtaPlatform SPI (which has a different package @@ -51,14 +52,14 @@ class ConfigurableJtaPlatform implements InvocationHandler { Class jpClass; try { // Try Hibernate 4.0-4.2 JtaPlatform variant - jpClass = SpringSessionContext.class.getClassLoader().loadClass( - "org.hibernate.service.jta.platform.spi.JtaPlatform"); + jpClass = ClassUtils.forName("org.hibernate.service.jta.platform.spi.JtaPlatform", + ConfigurableJtaPlatform.class.getClassLoader()); } catch (ClassNotFoundException ex) { try { // Try Hibernate 4.3 JtaPlatform variant - jpClass = SpringSessionContext.class.getClassLoader().loadClass( - "org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform"); + jpClass = ClassUtils.forName("org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform", + ConfigurableJtaPlatform.class.getClassLoader()); } catch (ClassNotFoundException ex2) { throw new IllegalStateException("Neither Hibernate 4.0-4.2 nor 4.3 variant of JtaPlatform found"); diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java index 51f802e42c..659afaf09b 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java @@ -94,7 +94,7 @@ public class LocalSessionFactoryBuilder extends Configuration { try { @SuppressWarnings("unchecked") Class converterAnnotation = (Class) - LocalSessionFactoryBuilder.class.getClassLoader().loadClass("javax.persistence.Converter"); + ClassUtils.forName("javax.persistence.Converter", LocalSessionFactoryBuilder.class.getClassLoader()); entityTypeFilters.add(new AnnotationTypeFilter(converterAnnotation, false)); } catch (ClassNotFoundException ex) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java index 86b2c7fb1b..fa8a7a13a4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java @@ -117,7 +117,7 @@ public class DefaultPersistenceUnitManager try { @SuppressWarnings("unchecked") Class converterAnnotation = (Class) - DefaultPersistenceUnitManager.class.getClassLoader().loadClass("javax.persistence.Converter"); + ClassUtils.forName("javax.persistence.Converter", DefaultPersistenceUnitManager.class.getClassLoader()); entityTypeFilters.add(new AnnotationTypeFilter(converterAnnotation, false)); } catch (ClassNotFoundException ex) {