spring-boot 免xml配置直接使用spring

spring-boot在maven的dependency里配置URL为:http://repo.spring.org/milestone以后,maven会自行下载spring-boot的依赖 spring


要使用spring-boot,首先要使用spring-annotationmaven

对于全部的bean要标注:@Componentspring-boot

切面要标注:@Aspect ,@Pointcut,@After等.net

对于主类,要标注:@Configuration,@Componentscancomponent

以后spring-boot会自行搜索全部的标注了component等标记的类,并在spring中注册。开发

为了可以使注册生效,对于须要调用的类,不能直接New,必须使用spring的ApplicationContext的getBean()方法生成才行。get


spring-boot虽然刚起步,可是确实开发使用起来很是方便,尤为对于那些动辄就要写XML的环境,很是建议使用spring-boot。有些人认为这种将配置写到代码中的方法很差,之后很差修改。但实际上在软件工程中,已经生成了的组件一般都不该该再被改变!于是使用spring-boot将迫使开发人员养成更好的开发习惯。io

相关文章
相关标签/搜索