dao,service,controller里面交给spring管理的注解(@Component)
*
@Repository 用于对DAO实现类进行标注
*
@Service 用于对Service实现类进行标注
*
@Controller 用于对Controller实现类进行标注
自动装配bean ,自定义的要用@Autowired
*
@Autowired 默认按照类型进行注入
如果存在两个相同Bean类型相同,则按照名称注入
*
@Autowired注入时可以针对成员变量或者setter方法
可以使用xml里id名字,也可使用反射方式。
@PostConstruct初始化=init-method
@PreDestroy销毁=destory-method
@Scope指定Bean的作用范围
@Bean注册一个Bean
@Configuration 指定pojo为Sprig提供Bean信息
2、在配置文件中添加context:annotation-config标签
context:annotation-config/
使@Resource、@ PostConstruct、@ PreDestroy、@Autowired注解生效
Bean定义
@Component
衍生类@Repository
@Service @Controller
@Configuration标注类,@Bean标注提供Bean方法
Bean名称
通过 id或name指定
@Component(“person”)
@Bean(“person”)
Bean注入
或者 通过p命名空间
@Autowired 按类型注入
@Qualifier按名称注入
在方法内部编写注入代码逻辑
生命过程、Bean作用范围
init-method
destroy-method
范围 scope属性
@PostConstruct 初始化
@PreDestroy 销毁
@Scope设置作用范围
在方法内部调用初始化方法
@Scope指定范围
适合场景
Bean来自第三方,使用其它命名空间
Bean的实现类由用户自己开发
实例化Bean的逻辑比较复杂
dao,service,controller里面交给spring管理的注解(@Component)
*
@Repository 用于对DAO实现类进行标注
*
@Service 用于对Service实现类进行标注
*
@Controller 用于对Controller实现类进行标注
自动装配bean ,自定义的要用@Autowired
*
@Autowired 默认按照类型进行注入
*
如果存在两个相同Bean类型相同,则按照名称注入
*
@Autowired注入时可以针对成员变量或者setter方法
可以使用xml里id名字,也可使用反射方式。
@PostConstruct初始化=init-method
@PreDestroy销毁=destory-method
@Scope指定Bean的作用范围
@Bean注册一个Bean
@Configuration 指定pojo为Sprig提供Bean信息
2、在配置文件中添加context:annotation-config标签
context:annotation-config/
使@Resource、@ PostConstruct、@ PreDestroy、@Autowired注解生效
Bean定义
@Component
衍生类@Repository
@Service @Controller
@Configuration标注类,@Bean标注提供Bean方法
Bean名称
通过 id或name指定
@Component(“person”)
@Bean(“person”)
Bean注入
或者 通过p命名空间
@Autowired 按类型注入
@Qualifier按名称注入
在方法内部编写注入代码逻辑
生命过程、Bean作用范围
init-method
destroy-method
范围 scope属性
@PostConstruct 初始化
@PreDestroy 销毁
@Scope设置作用范围
在方法内部调用初始化方法
@Scope指定范围
适合场景
Bean来自第三方,使用其它命名空间
Bean的实现类由用户自己开发
实例化Bean的逻辑比较复杂