SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. RestTemplateBuilder class
  2.  
  3. public RestTemplate build() {
  4.         return build(RestTemplate.class);
  5.     }
  6.  
  7. public <T extends RestTemplate> T build(Class<T> restTemplateClass) {
  8.         return configure(BeanUtils.instantiate(restTemplateClass));
  9.     }
  10. -----
  11. BeanUtils class
  12. public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException {
  13.         Assert.notNull(clazz, "Class must not be null");
  14.         if (clazz.isInterface()) {
  15.             throw new BeanInstantiationException(clazz, "Specified class is an interface");
  16.         }
  17.         try {
  18.             return clazz.newInstance(); <--- create the instance of the passed class i.e. RestTemplate()
  19.         }
  20.         catch (InstantiationException ex) {
  21.             throw new BeanInstantiationException(clazz, "Is it an abstract class?", ex);
  22.         }
  23.         catch (IllegalAccessException ex) {
  24.             throw new BeanInstantiationException(clazz, "Is the constructor accessible?", ex);
  25.         }
  26.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top