Spring项目中会用到大量的注解,这里罗列以下常用的。除过这些外SpringBoot、SpringSecurity、SpringData等也有大量的注解。
可以通过package去查看官方文档里的具体说明,比如:
[url=http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html]http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html[/url]
Annotation Types Summary部分就是该package下所有注解的说明。
[img]http://dl2.iteye.com/upload/attachment/0123/6835/12257cee-41c7-3706-9934-85d295933c15.png[/img]
[b](1)Context[/b] [color=blue]org.springframework.context.annotation[/color]
@Configuration
@ComponentScan
@ComponentScans
@Conditional
@Bean
@Lazy
@DependsOn
@Import
@ImportResource
@Primary
@Profile
@Scope
@Description
@PropertySource
@PropertySources
@Role
[b](2)Bean[/b] [color=blue]org.springframework.beans.factory.annotation[/color]
@Autowired
@Qualifier
@Required
@Scope
@Lookup
@Value
@Configurable
[b](3)Core[/b] [color=blue]org.springframework.core.annotation[/color]
@Order
@AliasFor
[b](4)Stereotyping[/b] [color=blue]org.springframework.stereotype[/color]
@Component
@Controller
@Service
@Repository
[b](5)Web[/b] [color=blue]org.springframework.web.bind.annotation[/color]
@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
[b](6)Transaction[/b] [color=blue]org.springframework.transaction.annotation[/color]
@EnableTransactionManagement
@Transactional
[b](7)Cache[/b] [color=blue]org.springframework.cache.annotation[/color]
@EnableCaching
@CacheConfig
@Cacheable
@Caching
@CachePut
@CacheEvict
[b](8)Schedule[/b] [color=blue]org.springframework.scheduling.annotation[/color]
@EnableAsync
@Async
@EnableScheduling
@Scheduled
@Schedules
[b](9)Aspect[/b] [color=blue]org.aspectj.lang.annotation[/color]
@Aspect
@After
@AfterReturning
@AfterThrowing
@Around
@Before
@DeclareParents
@Pointcut
[b](10)JSR-250[/b] [color=blue]javax.annotation[/color]
@PostConstruct
@PreDestroy
@Resource
[b](11)JSR-330[/b] [color=blue]javax.inject[/color]
@Inject
@Named
[b](12)JSR-303[/b] [color=blue]javax.validation.constraints[/color]
@Max
@Min
@NotNull
@Size
@Pattern
@Valid
[b]Hibernate Validator[/b] [color=blue]org.hibernate.validator.constraints[/color]
@Email
@Length
@Digits
@NotEmpty
@NotBlank
@Range
@URL
@Past
@Future
[b](13)MyBatis[/b] [color=blue]org.apache.ibatis.annotations[/color]
@Param
@Select
@Update
@Delete
@Insert
@Results
@Result
@Options
[b](14)其他[/b]
@EnableWebMvc org.springframework.web.servlet.config.annotation
@Validated org.springframework.validation.annotation
@MapperScan org.mybatis.spring.annotation
@Alias org.apache.ibatis.type.Alias
[img]http://dl2.iteye.com/upload/attachment/0130/9934/694ce90a-03ec-3c21-b076-c498dd542548.png[/img]
[url=https://dzone.com/articles/15-spring-core-annotations-with-examples]https://dzone.com/articles/15-spring-core-annotations-with-examples[/url]
参考:
[url=https://dzone.com/refcardz/spring-annotations]https://dzone.com/refcardz/spring-annotations[/url]
可以通过package去查看官方文档里的具体说明,比如:
[url=http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html]http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/package-summary.html[/url]
Annotation Types Summary部分就是该package下所有注解的说明。
[img]http://dl2.iteye.com/upload/attachment/0123/6835/12257cee-41c7-3706-9934-85d295933c15.png[/img]
[b](1)Context[/b] [color=blue]org.springframework.context.annotation[/color]
@Configuration
@ComponentScan
@ComponentScans
@Conditional
@Bean
@Lazy
@DependsOn
@Import
@ImportResource
@Primary
@Profile
@Scope
@Description
@PropertySource
@PropertySources
@Role
[b](2)Bean[/b] [color=blue]org.springframework.beans.factory.annotation[/color]
@Autowired
@Qualifier
@Required
@Scope
@Lookup
@Value
@Configurable
[b](3)Core[/b] [color=blue]org.springframework.core.annotation[/color]
@Order
@AliasFor
[b](4)Stereotyping[/b] [color=blue]org.springframework.stereotype[/color]
@Component
@Controller
@Service
@Repository
[b](5)Web[/b] [color=blue]org.springframework.web.bind.annotation[/color]
@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
[b](6)Transaction[/b] [color=blue]org.springframework.transaction.annotation[/color]
@EnableTransactionManagement
@Transactional
[b](7)Cache[/b] [color=blue]org.springframework.cache.annotation[/color]
@EnableCaching
@CacheConfig
@Cacheable
@Caching
@CachePut
@CacheEvict
[b](8)Schedule[/b] [color=blue]org.springframework.scheduling.annotation[/color]
@EnableAsync
@Async
@EnableScheduling
@Scheduled
@Schedules
[b](9)Aspect[/b] [color=blue]org.aspectj.lang.annotation[/color]
@Aspect
@After
@AfterReturning
@AfterThrowing
@Around
@Before
@DeclareParents
@Pointcut
[b](10)JSR-250[/b] [color=blue]javax.annotation[/color]
@PostConstruct
@PreDestroy
@Resource
[b](11)JSR-330[/b] [color=blue]javax.inject[/color]
@Inject
@Named
[b](12)JSR-303[/b] [color=blue]javax.validation.constraints[/color]
@Max
@Min
@NotNull
@Size
@Pattern
@Valid
[b]Hibernate Validator[/b] [color=blue]org.hibernate.validator.constraints[/color]
@Length
@Digits
@NotEmpty
@NotBlank
@Range
@URL
@Past
@Future
[b](13)MyBatis[/b] [color=blue]org.apache.ibatis.annotations[/color]
@Param
@Select
@Update
@Delete
@Insert
@Results
@Result
@Options
[b](14)其他[/b]
@EnableWebMvc org.springframework.web.servlet.config.annotation
@Validated org.springframework.validation.annotation
@MapperScan org.mybatis.spring.annotation
@Alias org.apache.ibatis.type.Alias
[img]http://dl2.iteye.com/upload/attachment/0130/9934/694ce90a-03ec-3c21-b076-c498dd542548.png[/img]
[url=https://dzone.com/articles/15-spring-core-annotations-with-examples]https://dzone.com/articles/15-spring-core-annotations-with-examples[/url]
参考:
[url=https://dzone.com/refcardz/spring-annotations]https://dzone.com/refcardz/spring-annotations[/url]
本文列举了Spring项目中常用的注解,覆盖Context、Bean、Core、Stereotyping等多个方面,并提供了官方文档链接以便深入学习。

被折叠的 条评论
为什么被折叠?



