Spring 常用註解
Spring Bean
- @Autowired: 依類
類型,導入依賴之bean - @Resource: 依類
名稱,導入依賴之bean (ex. @Resource(name=”resourceName”)) - @Component: 標註任意類為Spring組件
- @Repository: 標註Dao層
- @Service: 業務邏輯類
- @Configuration: 配置
- @Bean: 宣告一Bean物件,交由Spring 管理
配置相關
- @Value: 在Spring管理之Bean中,可取得配置文件中的屬性值
參數檢查
- @NotEmpty: 不能NULL,不能空
- @NotBlank: 不能NULL,須包含一字元(不為空白字元)
其他
- @Transactional: 標註在
類或方法上,遇異常則rollback