On Java Development

All things related to Java development, from the perspective of a caveman.

Archive for the ‘Java Reflection’ Category

Using Java Reflection to call methods of a Java Class

without comments

Introduction

This post shows how to use Java Reflection to call getter methods of a Spring context bean (a POJO). The POJO contains the application’s property values and the values need to be logged to the application’s log-file during the application’s startup phase. Since the property name/value pairs differ across projects this means the bean’s method names for each property are also different since their names reflect the names of the properties. Traditional approaches to logging the property values means writing customized code to explicitly call each method by name. Adding to this, whenever a new property is added, the logic has to be modified to include a call to the new method.
Read the rest of this entry »

Written by admin

March 7th, 2014 at 6:03 am