package com.itheima.config.postprocessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
public class MyBeanFactory implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
System.out.println("bean的工厂制作好了,还有什么事情需要处理");
}
}
package com.itheima.config.postprocessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
public class MyBean implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println("bean之前巴拉巴拉");
System.out.println(beanName);
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("bean之后巴拉巴拉");
return bean;
}
}
package com.itheima.config;
import com.itheima.config.filter.MyTypeFilter;
import com.itheima.config.postprocessor.MyBean;
import com.itheima.config.postprocessor.MyBeanFactory;
import com.itheima.config.registrar.CustomeImportBeanDefinitionRegistrar;
import com.itheima.config.registrar.MyImportBeanDefinitionRegistrar;
import com.itheima.config.selector.CustomerImportSelector;
import com.itheima.config.selector.MyImportSelector;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Configuration
@ComponentScan("com.itheima")
@Import({MyBeanFactory.class, CustomeImportBeanDefinitionRegistrar.class, MyBean.class})
//@Import(CustomerImportSelector.class)
/*@ComponentScan(
value = "com.itheima",
excludeFilters = @ComponentScan.Filter(
type = FilterType.ANNOTATION,
classes = Service.class
)
)*/
/*@ComponentScan(
value = "com.itheima",
excludeFilters = @ComponentScan.Filter(
type = FilterType.CUSTOM,
classes = MyTypeFilter.class
)
)*/
public class SpringConfig {
}
package com.itheima.dao.impl;
import com.itheima.dao.EquipmentDao;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.InitializingBean;
public class EquipmentDaoImpl implements EquipmentDao,InitializingBean {
public void save() {
System.out.println("equipment dao running...");
}
@Override
//定义当前bean初始化操作,功效等同于init-method属性配置
public void afterPropertiesSet() throws Exception {
SqlSessionFactoryBean fb;
System.out.println("EquipmentDaoImpl......bean ...init......");
}
}
package com.itheima.dao.impl;
import org.springframework.beans.factory.FactoryBean;
public class EquipmentDaoImplFactoryBean implements FactoryBean {
@Override
public Object getObject() throws Exception {
return new EquipmentDaoImpl();
}
@Override
public Class<?> getObjectType() {
return null;
}
@Override
public boolean isSingleton() {
return FactoryBean.super.isSingleton();
}
}