注解注入类
请看例子:
applicationContext.xml
<!-- 对Web包的所有类进行扫描,完成Bean创建和自动依赖注入 --><context:component-scan base-package="com" />
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); }}