spring中Bean的个人理解
来源:互联网 发布:职场动物进化手册知乎 编辑:程序博客网 时间:2024/06/11 02:29
ioc注入bean 有3种方式:
1、set注入
2、构造注入
3、注解注入,即在实现类的上面添加@Service 等,添加注解的时候要注意,在xml配置文件中要添加全包扫描,这样spring会把扫描包下带有注解的加载成对应的bean放到context中
在调用bean的时候,在类中引用的方式如下,
1、set注入,构造注入,是在xml文件里面配置的。
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
然后调用getBean就可以找到他的实现类。
2、注解调用bean时候 是@Resource定义在接口的上面,并且此接口被实现了,并把实现类放到了ApplicationContext 中。不然会出现bean找不到等问题
mybatis中接口不添加@Service注解。只添加全包扫描配置,好用的原因是mybatis-spring框架中的xml已经实现了接口,并把对应名字的类放到的context中
说白了 就是调用bean的时候,必须是一个bean的实现类在ApplicationContext 中。然后用@Resource 或者 getBean方法获取对应的Bean的具体对象
阅读全文
0 0
- spring中Bean的个人理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中Bean及@Bean的理解
- Spring中bean的理解
- 对spring配置中bean的理解
- 我对Spring中<bean>的理解
- Spring中Bean的理解以及@Bean的作用
- spring bean 的理解
- spring-bean的理解
- 欢迎使用CSDN-markdown编辑器
- spring MVC:前端页面需要多显示一列,后端每层均需增加字段
- HDU6070(分数规划+线段树)
- React高阶组件
- 面试题
- spring中Bean的个人理解
- PHP 超级全局变量
- IntelliJ使用Maven创建SpringMVC服务
- Qt之二维码扫描
- jmeter函数助手对话框之参数详解
- c++创建链表
- Nginx 实现负载均衡
- js ==和===比较
- HDU6069 Counting Divisors(素数筛+二次筛)