Import Java.lang.reflect.Field;
Import Org.springframework.beans.beansexception;import Org.springframework.beans.factory.config.BeanPostProcessor;
public class Uppercasemodifier implements Beanpostprocessor {
@Overridepublic object Postprocessafterinitialization (object bean, String name)Throws Beansexception {TODO auto-generated Method StubSystem.out.println ("Object" + name + "instantiation complete");return bean;}
@Overridepublic object Postprocessbeforeinitialization (object bean, String name)Throws Beansexception {System.out.println ("Object" + Name + "Start instantiation");Fetch all attributes of beanfield[] fields = Bean.getclass (). Getdeclaredfields ();for (int i=0; i<fields.length; i++) {Determine the Name fieldif (Fields[i].getname (). Equals ("name")) {Set this field to accessFields[i].setaccessible (TRUE);try {String original = (string) fields[i].get (bean);System.out.println (original);Fields[i].set (Bean, original.touppercase ());} catch (Exception e) {E.printstacktrace ();}}}return bean;}
The above code implements the lowercase letters in the Name property value into uppercase letters; The Beanpostprocessor interface consists of two methods:
Postprocessafterinitialization: Operation after instantiation
Postprocessbeforeinitialization: Operation before instantiation
to introduce the class in the configuration file: <bean id="Uppercasemodifier" class="Uppercasemodifier" ></bean>The slag has to be stuck in the Bug.
From for notes (Wiz)
The use of Beanpostprocessor to manipulate objects before or after initialization of an object