Person[name=Jack,age=10]
style==null:Person@deb6432[name=Jack,age=10,password=Jack'sPassword]
SHORT_PREFIX_STYLE:Person[name=Jack,age=10,password=Jack'sPassword]
SIMPLE_STYLE:Jack,10,Jack'sPassword
MULTI_LINE_STYLE:Person@deb6432[
name=Jack
age=10
password=Jack'sPassword
]
NO_FIELD_NAMES_STYLE:Person@deb6432[Jack,10,Jack'sPassword]
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import java.lang.reflect.Field;
import java.util.Objects; public class StringUtilsDemo {
public static void main(String[] args) {
Person person = new Person();
person.setName("Jack");
person.setPassword("Jack'sPassword");
person.setAge((short) 10);
System.out.println("" + person);
System.out.println("style==null:" + ReflectionToStringBuilder.toString(person));
System.out.println("SHORT_PREFIX_STYLE:" + ReflectionToStringBuilder.toString(person, ToStringStyle.SHORT_PREFIX_STYLE));//截去了包名
System.out.println("SIMPLE_STYLE:" + ReflectionToStringBuilder.toString(person, ToStringStyle.SIMPLE_STYLE));
System.out.println("MULTI_LINE_STYLE:" + ReflectionToStringBuilder.toString(person, ToStringStyle.MULTI_LINE_STYLE));
System.out.println("NO_FIELD_NAMES_STYLE:" + ReflectionToStringBuilder.toString(person, ToStringStyle.NO_FIELD_NAMES_STYLE)); }
} class Person {
private String name;
private Short age;
private String password; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Short getAge() {
return age;
} public void setAge(Short age) {
this.age = age;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} @Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) {
@Override
protected boolean accept(Field field) {
return super.accept(field) && !Objects.equals(field.getName(), "password");
}
}.toString();
} }

package org.test.InitializingBean;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* 测试 spring的 InitializingBean 接口
* @author Administrator
*
*/
public class InitializingBeanTest { /**
* @param args
*/
public static void main(String[] args) { ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml",
InitializingBeanTest.class);
ctx.start(); } }
package org.test.InitializingBean;

import org.springframework.beans.factory.InitializingBean;

/**
* @see {@link org.springframework.beans.factory.InitializingBean#afterPropertiesSet}
* @author Administrator
*
*/
public class User implements InitializingBean { public User() {
System.out.println(">>>>>>> User 默认的构造函数执行了");
} @Override
public void afterPropertiesSet() throws Exception {
System.out.println(">>>>>>> 执行了 afterPropertiesSet 方法"); } }

执行的结果如下图所示。可以看到当执行完User默认的构造函数之后,就会调用该类实现afterPropertiesSet方法

InitializingBean afterPropertiesSet的更多相关文章

  1. spring中afterPropertiesSet方法与init-method配置描述

    1. InitializingBean.afterPropertiesSet()Spring中InitializingBean接口类为bean提供了定义初始化方法的方式,它仅仅包含一个方法:after ...

  2. Spring的InitializingBean与DisposableBean方法

    在bean初始化的时候,将所有显示提供的属性设置完毕后调用这个方法 org.springframework.beans.factory.InitializingBean#afterProperties ...

  3. Spring框架中InitializingBean执行顺序

    本文转自:https://www.cnblogs.com/yql1986/p/4084888.html package org.test.InitializingBean; 2 3 import or ...

  4. spring bean中构造函数,afterPropertiesSet和init-method的执行顺序

    http://blog.csdn.net/super_ccc/article/details/50728529 1.xml文件 <bean id="aaa" class=&q ...

  5. spring源码分析之freemarker整合

    FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它不是面向最终用户的,而是一个Java类库,是一款程 ...

  6. Spring Bean的生命周期(非常详细)

    Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的.我们通常使用ApplicationContext作为Spring ...

  7. Spring Bean的加载

    Spring加载bean的原则:不等bean创建完成就会将创建bean的ObjectFactory提早曝光加入到缓存中.   单例bean在Spring容器里只会创建一次,后续创建时会首先从缓存中获取 ...

  8. Spring+quartz 实现定时任务job集群配置

    为什么要有集群定时任务? 因为如果多server都触发相同任务,又同时执行,那在99%的场景都是不适合的.比如银行每晚24:00都要汇总营业额.像下面3台server同时进行汇总,最终计算结果可能是真 ...

  9. spring容器对bean生命周期的管理三中方式

    spring容器对bean的生命周期管理主要在两个时间点:bean的初始化完成(包括属性值被完全注入),bean的销毁(程序结束,或者引用结束)方式一:使用springXML配置中的init-meth ...

随机推荐

  1. 【转】MySQL数据库原理

    原文地址:http://www.cnblogs.com/qiuyi116/p/4349233.html 我们知道,数据是信息的载体——一种我们约定了如何解释的符号.在计算机系统中,最常见的应该是文本数 ...

  2. [Albert 朗读行动记录贴]采纳Scalers方法:口语成长行动

    目标:100小时成长计划,持续朗读录音100小时. 行动计划:每天点评美音3个人的朗读,英音1个. 完成朗读计划,录一段.附录一段.1分半左右. 开始日期:3月18日 原帖: [335][合辑]Sca ...

  3. redis hash怎么用

    public static void testHsh() { System.out.println("==Hash=="); Jedis jedis = RedisUtil.get ...

  4. tomcat bug之部署应用的时候经常会发上startup failed due to previous errors

    在tomcat上部署应用的时候经常会发上startup failed due to previous errors错误.这个错误产生以后经常会让人摸不到头脑.以下是几点查找经验: 1.web.xml文 ...

  5. 使用webdriver + phantomjs + pdfkit 生成PDF文件

    实例 #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on Dec 6, 2013 @author: Jay <smile665@gm ...

  6. C++的函数名重载

    #include <iostream> using namespace std; int func(int c) { cout<<"int func(int c)&q ...

  7. Rails--content_for和yield

    --使用: (1)layout中使用<%=yield(:js)%> (2)html中使用<% content_for :js do %>[XXX]<% end %>

  8. java--字符串替换replace,replaceAll,replaceFirst

    1.字符串替换,replace string s="abcdfersabcdsgacabc"; 将字符串中的abc替换成bdf s.replace("abc", ...

  9. Amoeba基本配置

    Amoeba安装及读写分离配置一.amoeba简介官网:http://docs.hexnova.com/amoeba/index.html二.Centos下安装jdk1.yum 安装1.6版本jdk2 ...

  10. buffer overflow vulnerabilitie

    Computer Systems A Programmer's Perspective Second Edition Avoiding security holes.For many years,bu ...