Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RestTemplateBuilder class
- public RestTemplate build() {
- return build(RestTemplate.class);
- }
- public <T extends RestTemplate> T build(Class<T> restTemplateClass) {
- return configure(BeanUtils.instantiate(restTemplateClass));
- }
- -----
- BeanUtils class
- public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException {
- Assert.notNull(clazz, "Class must not be null");
- if (clazz.isInterface()) {
- throw new BeanInstantiationException(clazz, "Specified class is an interface");
- }
- try {
- return clazz.newInstance(); <--- create the instance of the passed class i.e. RestTemplate()
- }
- catch (InstantiationException ex) {
- throw new BeanInstantiationException(clazz, "Is it an abstract class?", ex);
- }
- catch (IllegalAccessException ex) {
- throw new BeanInstantiationException(clazz, "Is the constructor accessible?", ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement