Spring的 注入和调用是很灵活的 手动配置和注解形式可以同时存在
来源:互联网 发布:游戏内存优化软件 编辑:程序博客网 时间:2024/05/20 16:00
1.先说action中调用spring服务,那么常见的方式
private QueryGlobalConstantDao queryGlobalConstantDaoImpl;
public void setQueryGlobalConstantDaoImpl(
QueryGlobalConstantDao queryGlobalConstantDaoImpl) {
this. queryGlobalConstantDaoImpl = queryGlobalConstantDaoImpl;
}
其中这个声明的名称 queryGlobalConstantDaoImpl 是要和注入的service的名称一样的~~
当然 如果在spring的配置文件中加上
xmlns:context ="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
那就是打开了content注解的方式注入和调用bean
然后 写上
<context:annotation-config />
<context:component-scan base-package= "com.smartshown.inner.service.impl" />
这两行其中的一个,我们就可以
@Resource(name="queryGlobalConstantDaoImpl")
private QueryGlobalConstantDao queryGlobalConstantDaoImpl;
来调用bean。。。。。。。。。spring支持两种调用方式同时存在,也支持下面说的注入方式两种 同时存在~
2.bean的注入,如上说的 不使用注解,普通的注入方式
<bean name ="pmpUserServiceImpl" class= "com.smartshown.inner.service.impl.PmpUserServiceImpl" >
<property name ="pmpUserDaoImpl" ref= "pmpUserDaoImpl"></property >
</bean >
打开注解的方式就上上面说的
<context:component-scan>和
<context:annotation-config /><context:component-scan>除了具有
<context:annotation-config />的功能之外,还具有自动将带有@component,@service,@Repository等注解的对象注册到spring容器中的功能 其实我们可以两句都写上,spring也会只注入一次的。常用的就是 @Service("aaaa")
调用 @Resource(name ="aaaa")
0 0
- Spring的 注入和调用是很灵活的 手动配置和注解形式可以同时存在
- 【SSH】注解和非注解的形式配置Spring
- Spring框架学习【解析和注入注解配置的资源】
- spring注解注入的配置
- spring注解源码分析-解析和注入注解配置的资源
- 基于注解的形式在Spring中实现对多数据源配置和使用
- spring自动注入和注解配置
- [Spring]基于注解的形式配置Bean
- Spring的注解形式
- Spring的注解形式
- Spring MVC中,基于XML配置和基于注解的依赖注入实例
- 有关spring的依赖注入和@resource注解的使用
- Spring 全注解配置 bean 和 调用 (7) properties文件注入
- spring-依赖注入的注解配置
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- Spring对注解(Annotation)处理源码分析2——解析和注入注解配置的资源
- androiod开发中出现Can't create handler inside thread that has not called Looper.prepare()的错误。
- 22点性能优化之Android开发
- json序列化和反序列化2
- 优化计算
- SIFT特征提取分析
- Spring的 注入和调用是很灵活的 手动配置和注解形式可以同时存在
- 破解solidorks2014成功经验
- 重建控制文件之后
- mysql主从复制
- oracle的shared memory realm does not exist这个错怎么解决? oracle ORA-01033(01034)问题怎么解决
- jdk5.0新特性之定义变长参数函数
- 不一样的购物新体验 惠折网试用报告
- input子系统
- 获取当前连接Wi-Fi 及 mac 地址