Annottions Springboot
Annottions Springboot
@SpringBootApplication
o Example:
o @SpringBootApplication
o SpringApplication.run(MyApplication.class, args);
o }
o }
@Configuration
o Example:
o @Configuration
o @Bean
o }
o }
@EnableAutoConfiguration
o Included in @SpringBootApplication.
@ComponentScan
o Example:
o @ComponentScan(basePackages = "com.example.service")
@RestController
o Example:
o @RestController
o @GetMapping("/hello")
o }
o }
@Controller
@RequestMapping
o Example:
o @RequestMapping("/api")
o @GetMapping("/users")
o return userService.findAll();
o }
o }
o Example:
o @PostMapping("/add")
o userService.save(user);
o }
@PathVariable
o Example:
o @GetMapping("/users/{id}")
o return userService.findById(id);
o }
@RequestParam
o Example:
o @GetMapping("/search")
o return userService.searchByName(name);
o }
@RequestBody
o Example:
o @PostMapping("/users")
o public void addUser(@RequestBody User user) {
o userService.save(user);
o }
@ResponseBody
@Component
o Example:
o @Component
@Service
@Repository
@Autowired
o Example:
o @Service
o @Autowired
o }
@Qualifier
o Example:
o @Autowired
o @Qualifier("specificBean")
@Value
o Example:
o @Value("${app.name}")
@Entity
o Example:
o @Entity
@Id
@GeneratedValue
o Example:
o @Id
o @GeneratedValue(strategy = GenerationType.IDENTITY)
@Table
o Example:
o @Table(name = "users")
@Repository
o @Repository
@Bean
o Example:
o @Bean
o }
@Profile
o Example:
o @Profile("dev")
o @Bean
@PropertySource
o Example:
o @PropertySource("classpath:application.properties")
6. Security Annotations
@PreAuthorize
o Example:
o @PreAuthorize("hasRole('ADMIN')")
@EnableWebSecurity
@Secured
o Example:
o @Secured("ROLE_ADMIN")