Spring项目中会用到大量的注解,这里罗列以下常用的。除过这些外SpringBoot、SpringSecurity、SpringData等也有大量的注解。
可以通过package去查看官方文档里的具体说明,比如:
http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html
Annotation Types Summary部分就是该package下所有注解的说明。
(1)Context
org.springframework.context.annotation
@Configuration
@ComponentScan
@ComponentScans
@Conditional
@Bean
@Lazy
@DependsOn
@Import
@ImportResource
@Primary
@Profile
@Scope
@Description
@PropertySource
@PropertySources
@Role
(2)Bean
org.springframework.beans.factory.annotation
@Autowired
@Qualifier
@Required
@Scope
@Lookup
@Value
@Configurable
(3)Core
org.springframework.core.annotation
@Order
@AliasFor
(4)Stereotyping
org.springframework.stereotype
@Component
@Controller
@Service
@Repository
(5)Web
org.springframework.web.bind.annotation
@Controller
@ControllerAdvice
@InitBinder
@ModelAttribute
@MatrixVariable
@RequestMapping
@RequestParam
@RequestPart
@RequestBody
@RequestHeader
@RequestAttribute
@SessionAttribute
@SessionAttributes
@CookieValue
@ExceptionHandler
@CrossOrigin
@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping
@RestController
@RestControllerAdvice
@ResponseBody
@ResponseStatus
@PathVariable
(6)Transaction
org.springframework.transaction.annotation
@EnableTransactionManagement
@Transactional
(7)Cache
org.springframework.cache.annotation
@EnableCaching
@CacheConfig
@Cacheable
@Caching
@CachePut
@CacheEvict
(8)Schedule
org.springframework.scheduling.annotation
@EnableAsync
@Async
@EnableScheduling
@Scheduled
@Schedules
(9)Aspect
org.aspectj.lang.annotation
@Aspect
@After
@AfterReturning
@AfterThrowing
@Around
@Before
@DeclareParents
@Pointcut
(10)JSR-250
javax.annotation
@PostConstruct
@PreDestroy
@Resource
(11)JSR-330
javax.inject
@Inject
@Named
(12)JSR-303
javax.validation.constraints
@Max
@Min
@NotNull
@Size
@Pattern
@Valid
Hibernate Validator
org.hibernate.validator.constraints
@Email
@Length
@Digits
@NotEmpty
@NotBlank
@Range
@URL
@Past
@Future
(13)MyBatis
org.apache.ibatis.annotations
@Param
@Select
@Update
@Delete
@Insert
@Results
@Result
@Options
(14)其他
@EnableWebMvc org.springframework.web.servlet.config.annotation
@Validated org.springframework.validation.annotation
@MapperScan org.mybatis.spring.annotation
@Alias org.apache.ibatis.type.Alias
参考:
https://dzone.com/refcardz/spring-annotations
Spring 注解大全
猜你喜欢
转载自rensanning.iteye.com/blog/2362086
今日推荐
周排行