1.通过xml的方式配置
2.通过注解配置:
@Component普通的对象
@Service业务层对象
@Controller控制层对象
@Repository是dao层对象
记得配置扫描包<component-scan>
3.javaConfig:@Bean注解
4.@Import 3种方式
1)在配置类上配置@Import注解,并定义要创建的bean.class;容器启动后就会自动创建
2)使用ImportSelector,实现ImportSelector接口
3)使用 ImportBeanDefinitionRegistrar,实现ImportBeanDefinitionRegistrar接口