javaConfig&springBoot入门
1. javaConfig基础
1.1 为什么要学习javaConfig
因为:Springboot原理基于它的!!!(为学习springBoot打下基础)
1.2 Java 的 bean 配置(JavaConfig)出现历史
spring1.x:xml配置
spring2.x:注解配置(打注解,扫描注解)
spring3.x-4.x javaconfig&springboot
Spring5.x
2. JavaConfig操作
2.1 spring测试方式
方式一:new ClassPathXmlApplicationContext
方式二:注入:Runwith ContextConfigration
2.2 xml配置
<bean id="myDate" class="java.util.Date">
2.3 注解配置
1. 打注解
2.4 javaconfig配置
基本:
配置类:@Configration 代替了xml配置文件
@Bean 代替了<bean>
扫描包:
bean扫描(@ComponentScan/ComponentScans)
Bean详情:
@Condition按条件注入:
1.条件类创建(实现Condition接口)
2.@Condition添加到类或者方法上面
@Import导入bean:
创建bean的方式
方式1:@ComponentScan+注解(@Controller+@Service+@Repository+@Compont)-自己创建的bean
方式2:@Bean 别人的bean
方式3:@Import(快速向容器中注册一个bean)
要导入的组件),名称就是累的全限定名
导入选择器,返回需要导入组件类的全限定名数组-springboot底层用的多
java基础注解配置
3)ImportBeanDefinitionRegistrar:通过bean定义注册器手动项目spring中容器中注册
@Import(value = {GreenColor.class, YellowColor.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
方式4:FactoryBean的方式,返回的是getObject的类实例-和其他框架集成是用的多
3. springBoot入门
3.1 步骤
一 创建项目
parent
dependency
二 创建springboot项目并且启动
)任意类加上@SpringBootApplication
)Main函数启动springboot的应用
三 写一个Contorller来测试
HelloConroller
3.2 打包
1.导入插件
2.打包
3. 运行
窗口运行:java -jar xxx.jar
后台运行: nohup java -jar XXX.jar & 只linux
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/h6javajc/18631.html