本文共 1385 字,大约阅读时间需要 4 分钟。
1.package spring.chapter2.setDemo; 2.import org.springframework.context.ApplicationContext; 3.import org.springframework.context.support.ClassPathXmlApplicationContext; 4. 5. 6.public class SpringTest { 7.public static void main(String args[]){ 8. ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); 9. Role role =(Role)ac.getBean("role"); 10. System.out.println("人物名称:"+role.getName()+" 血量: "+role.getHealth()); 11.} 12.package spring.chapter2.setDemo; 13.import java.lang.reflect.*; 14.import org.springframework.beans.BeansException; 15.import org.springframework.beans.factory.config.BeanPostProcessor; 16. 17.public class HealthModifier implements BeanPostProcessor { 18./*//游戏外挂么!@ 19. * 20. * 21. * 22. * 23. * 24. * 25.*/ public Object postProcessAfterInitialization(Object bean,String name)throws BeansException 26. { 27. //获取bean中所有的属性 28. Field[] fields =bean.getClass().getDeclaredFields(); 29. for(int i=0;i61. 64. 65. 81. }66. 69.67. 68. 70. 78. 79.71. 72. 73. 76. 77.80.
转载地址:http://lnuix.baihongyu.com/