不太明白spring中每个注解的含义,初步了解常用注解记录如下:
@Controller 声明Action组件
@Service 声明Service组件 @Service("myMovieLister")
@Repository 声明Dao组件
@Component 泛指组件, 当不好归类时.
@RequestMapping("/apple") 请求映射
@Resource 用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName")
@Autowired 用于注入,(srping提供的) 默认按类型装配
@Transactional( rollbackFor={Exception.class}) 事务管理
@ResponseBody
@Scope("prototype") 设定bean的作用域
@SuppressWarnings("finally")
J2SE 提供的最后一个批注是 @SuppressWarnings。该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默。
@Autowired是Spring提供的一种注入Bean的方法。 具体的应用是: 1)在Service类中定义的注入属性前加@Autowired。例如:@Autowired private PersonDAO personDAO, 2)必须有个set方法,例如: @Autowired public void setPersonDAO(PersonDAO personDAO) { System.out.println("********** @Autowired注入Bean *************"); this.personDAO = personDAO; } Spring配置文件的配置内容: 1) 头部 (加入)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" 2) <context:annotation-config/> <bean id="personDAO" class="edu.syict.dao.impl.PersonDAOImpl"/> <bean id="personService" class="edu.syict.service.impl.PersonServiceImpl"/> 有问题发信息。