new 出的对象,无法调用@Autowired进入的spring bean
来源:互联网 发布:金山数据恢复软件多大? 编辑:程序博客网 时间:2024/05/18 20:06
原文出处:http://blog.sina.com.cn/s/blog_6151984a0100oy98.html
@Autowired来的spring 下的bean,则当前类必须也是spring bean才能调用它,不能用new Xxx()来获得对象,这种方式获得的对象无法调用其内的@autowired的bean
1. 类1
加入spring poolpublic class PersonServiceImpl implements PersonService{
}
加入spring pool
<bean id="personServiceImpl" class="com.machome.testtip.impl.PersonServiceImpl" >
</bean>2.类2
autowired类1, 并且也加入spring poolpublic class ProxyPServiceImpl implements ProxyPService {
}3.直接new类2,则执行其方法时出null pointer错误ProxyPService
proxyPService.save();
执行报错:
java.lang.NullPointerException
try {
new ClassPathXmlApplicationC
proxyPService.save();
执行:
this is proxy say:This is save for test spring
阅读全文
0 0
- new 出的对象,无法调用@Autowired进入的spring bean
- new 出的对象,无法调用@Autowired进入的spring bean
- new出来的对象无法调用@Autowired注入的Spring Bean
- new 出的对象无法使用 @Autowired装配进来的属性,会报null
- Servlet @Autowired Spring Bean 的方法 .
- spring bean-- autowired的正确用法
- Spring 如何将无法使用new操作符新建的对象作为spring的bean (使用FactoryBean接口)
- 被@Autowired的对象不能再new
- new对象与Spring对bean的初始化的差别
- 使用@Autowired自动装配对象和new对象的区别
- Spring的bean的装配 @Componen @ComponentScan @Autowired
- Spring Boot 普通类调用Bean对象的一种方式
- Spring 使new方法创建的对象可以引用spring管理的bean.
- Spring学习笔记(十):@Autowired和new的区别
- new类加载spring托管的bean
- Spring中bean的调用
- 【Spring】bean对象的创建
- servlet中无法直接autowired bean from Spring
- nova的unshelve的log
- 利用C#代码创建、查看、删除端口转发
- synchronized给并发操作加一把锁
- 运输层UDP协议
- Mysql使用存储过程和游标
- new 出的对象,无法调用@Autowired进入的spring bean
- 跨站请求伪造攻击(CSRF)的预防
- JavaScript的用法
- Java 中 9 个处理 Exception 的最佳实践
- 欢迎使用CSDN-markdown编辑器
- MyBatis之动态sql
- jquery获取select框当前选中的那一项
- Windows的cd命令
- 移动端UI自动化测试框架对比