Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement