java - 为什么没有使用@autowired 和@component 类创建对象?
问题描述
//主类
@SpringBootApplication
public class SpringBootTest{
public static void main(String[] args){
SpringApplication.run(SpringBootTest.class,args);
A a=new A();
a.method();
B b=new B();
b.method1();
}
}
AmqpTemplate 的包是 import org.springframework.amqp.core.AmqpTemplate;
@Component
public class A{
@Autowired
AmqpTemplate obj;
public void method(){
System.out.println(obj);
}
}
//B类
@Component
public class B{
@Autowired
A obj1;
public void method1(){
System.out.println(obj1);
}
}
为什么B类中的Obj1和B类中的obj在执行代码后为空?任何帮助将不胜感激。
解决方案
推荐阅读
- vue.js - 在插件中访问 Nuxt Router
- .htaccess - .htaccess 父文件夹未完全覆盖
- python - Python和openssl的安装---不用yum
- neo4j - 使用变量匹配并在同一变量的结果之间创建关系
- html - 如何防止谷歌网络爬虫将单个页面作为两个不同的页面读取
- javascript - Discord.js 等待 setTimeout 函数完成,然后允许它再次运行
- python - 无法在pycharm中安装dlib
- javascript - 尝试使用 javascript 使用 localStorage.setItem 保存和加载游戏状态但收到类型错误
- python - Tensorflow TPU 错误:随机缓冲区已满?
- java - (单元测试)如何保持扫描仪运行(Java)