首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

引文注入类

2012-06-26 
注解注入类请看例子:applicationContext.xml!-- 对Web包的所有类进行扫描,完成Bean创建和自动依赖注入 --

注解注入类
请看例子:
applicationContext.xml

<!-- 对Web包的所有类进行扫描,完成Bean创建和自动依赖注入 --><context:component-scan base-package="com" />


ArithmeticService.java
package com;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;@Service("springService")@Transactionalpublic class ArithmeticService {public Integer add(Integer operand1, Integer operand2) {// A simple arithmetic additionreturn operand1 + operand2;}}


@Controllerpublic class TestVo {@Resource(name="springService")private ArithmeticService springService;public void test(){            //将返回3            springService.add(1,2);        }}

热点排行