package com.zzw.springboot;
import com.zzw.springboot.bean.Cat;
import com.zzw.springboot.bean.Dog;
import com.zzw.springboot.bean.Monster;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
/**
* @author 赵志伟
* @version 1.0
*/
@SuppressWarnings({"all"})
/**
* @SpringBootApplication: 表示这是一个springboot引用/项目
* @SpringBootApplication(scanBasePackages = "com.zzw")
* 解读: scanBasePackages = "com.zzw" 指定SpringBoot要扫描的包和子包
* 如果有多个包, 可以这样指定: 用数组 scanBasePackages = {"com.zzw","xxx.yyy.zzz"}
*/
@SpringBootApplication(scanBasePackages = "com.zzw")
public class MainApp {
public static void main(String[] args) {
//启动springboot应用程序/项目
ApplicationContext ioc = SpringApplication.run(MainApp.class, args);
//如何查看容器中注入的组件
//① 打断点
//② 写代码
//String[] beanDefinitionNames = ioc.getBeanDefinitionNames();
//for (String beanDefinitionName : beanDefinitionNames) {
// System.out.println("beanDefinitionName=" + beanDefinitionName);
//}
//演示Spring中传统的注解依然可以使用 @controler @service @repository
//A aBean = ioc.getBean(A.class);
//System.out.println("aBean=" + aBean);
//=====演示在springboot项目,依然可以使用spring的配置bean/注入bean/获取bean方式 start===
//ApplicationContext ac =
// new ClassPathXmlApplicationContext("beans.xml");
//Monster monster = ac.getBean("monster" , Monster.class);
//System.out.println("monster=" + monster);
//=====演示在springboot项目,依然可以使用spring的配置bean/注入bean/获取bean方式 end=====
//=====演示在springboot项目中,@Configuration的使用 start===
//Monster monster01 = ioc.getBean("monster01" , Monster.class);
//Monster monster02 = ioc.getBean("monster01" , Monster.class);
//System.out.println("monster01=" + monster01 + " " + monster01.hashCode());
//System.out.println("monster02=" + monster02 + " " + monster02.hashCode());
//=====演示在springboot项目中,@Configuration的使用 end=====
//=====演示 配置类-bean也会注入到容器 start===
//BeanConfig beanConfig = ioc.getBean("beanConfig", BeanConfig.class);
//System.out.println("beanConfig=" + beanConfig + " " + beanConfig.hashCode());//beanConfig=com.zzw.springboot.config.BeanConfig$$EnhancerBySpringCGLIB$$ff5fd0e4@45cec376 1171178358
//=====演示 配置类-bean也会注入到容器 end=====
//=====演示 @Configuration(proxyBeanMethods = xxx) start===
//1.先得到BeanConfig组件
//BeanConfig beanConfig = ioc.getBean("beanConfig", BeanConfig.class);
//Monster monster_01 = beanConfig.monster01();
//Monster monster_02 = beanConfig.monster01();
//System.out.println("monster_01--" + monster_01 + " " + monster_01.hashCode());
//System.out.println("monster_02--" + monster_02 + " " + monster_02.hashCode());
//特别说明: proxyBeanMethods 是在 调用@Bean方法 才生效. 因此, 需要先获取BeanConfig 组件, 再调用方法
//1. 而不是直接通过 SpringBoot 主程序得到的容器来获取bean, 注意观察直接通过ioc.getBean() 获取Bean, proxyBeanMethods 值并没有生效
//Monster monster01 = ioc.getBean("monster01", Monster.class);
//Monster monster02 = ioc.getBean("monster01", Monster.class);
//System.out.println("monster01--" + monster01 + " " + monster01.hashCode());
//System.out.println("monster02--" + monster02 + " " + monster02.hashCode());
//=====演示 @Configuration(proxyBeanMethods = xxx) end===
//=====测试可以有多个配置类 start===
//两个配置类注入的Bean都生效
//Monster monster02 = ioc.getBean("monster02", Monster.class);
//Monster monster01 = ioc.getBean("monster01", Monster.class);
//System.out.println("monster02--" + monster02);
//System.out.println("monster01--" + monster01);
//=====测试可以有多个配置类 end===
//=====测试@Import 使用 start===
//Dog dogBean = ioc.getBean(Dog.class);
//Cat catBean = ioc.getBean(Cat.class);
//System.out.println("dogBean---" + dogBean);
//System.out.println("catBean---" + catBean);
//=====测试@Import 使用 end===
//=====测试@ConditionalOnBean 使用 start===
//Dog dog01 = ioc.getBean("dog01", Dog.class);
//System.out.println("dog01---" + dog01);
//=====测试@ConditionalOnBean 使用 end===
//=====演示@ImportResource 使用 start===
Monster monster = ioc.getBean("monster", Monster.class);
System.out.println("monster---" + monster);
System.out.println("monster bean 是否存在-" + ioc.containsBean("monster"));
Monster monster03 = ioc.getBean("monster03", Monster.class);
System.out.println("monster03---" + monster03);
System.out.println("monster03 bean 是否存在-" + ioc.containsBean("monster03"));
//=====演示@ImportResource 使用 end===
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![chm](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
共 36 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/19ef046228bd4bb29bff504883ac6056_qq_18817831.jpg!1)
~小团子
- 粉丝: 718
- 资源: 66
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)