✅ Spring Boot Annotations

๐Ÿ 1. Main Application Setup

๐Ÿ”ฐ @SpringBootApplication – This is a convenience annotation that combines: @Configuration, @EnableAutoConfiguration, and @ComponentScan. It is used on the main class to bootstrap and launch a Spring Boot application.
  • @Configuration – Indicates that the class contains Spring bean definitions. Beans defined here will be registered in the application context.
  • @EnableAutoConfiguration – Tells Spring Boot to automatically configure beans based on the classpath, properties, and existing beans. Helps reduce manual configuration.
  • @ComponentScan – Enables automatic scanning of packages for components like @Component, @Service, @Repository, and @Controller.

๐Ÿงฉ 2. Component & Bean Annotations

๐Ÿงฉ@Component - Spring-managed component (auto-detected).
๐Ÿ”ง@Service - For business logic layer.
๐Ÿ—ƒ️@Repository - For data access layer with exception translation.
๐ŸŽฎ@Controller - Defines a web controller (MVC, returns views).
๐ŸŒ@RestController - Combines @Controller and @ResponseBody, returns JSON/XML.
๐Ÿงช@Bean - Manually declares a Spring bean inside @Configuration class.

๐Ÿงท 3. Dependency Injection

๐Ÿ“Œ@Autowired - Automatically injects dependencies.
๐ŸŽฏ@Qualifier("beanName") - Specifies which bean to inject when multiple exist.
๐Ÿ“@Value("${property.name}") - Injects values from properties file.

๐ŸŒ 4. Web Request Mapping

๐ŸŒ@RequestMapping("/path") - Generic HTTP mapping.
๐Ÿ“ฅ@GetMapping("/path") - Shortcut for GET requests.
๐Ÿ“ค@PostMapping, ๐Ÿ”„@PutMapping, ๐Ÿ—‘️@DeleteMapping, ๐Ÿฉน@PatchMapping - For respective HTTP methods.
๐Ÿงญ@PathVariable - Binds URL path variable (e.g., /user/{id}).
๐Ÿ”Ž@RequestParam - Binds query parameters (e.g., ?name=John).
๐Ÿ“ฆ@RequestBody - Binds request body to Java object.
๐Ÿ“ค@ResponseBody - Returns object as JSON/XML in HTTP response.

๐Ÿ—ƒ️ 5. JPA & Database

๐Ÿท️@Entity - Declares a JPA entity (maps to DB table).
๐Ÿงพ@Table(name = "users") - Specifies custom table name.
๐Ÿ†”@Id - Defines primary key.
๐Ÿ”ข@GeneratedValue - Auto-generates primary key.
๐Ÿ“„@Column(name = "email") - Maps field to DB column.

๐Ÿ”’ 6. Transactions

๐Ÿ”’@Transactional - Wraps method/class in a DB transaction.

๐Ÿงช 7. Testing Annotations

๐Ÿงช@SpringBootTest - Loads full app context for integration testing.
๐Ÿงผ@WebMvcTest - Loads only controller/web layer.
๐Ÿ“Š@DataJpaTest - For JPA repository testing with in-memory DB.
๐Ÿงฑ@MockBean - Adds a mock bean (overrides real one in tests).

⚙️ 8. Profile & Configuration

⚙️@Configuration - Defines Spring beans using @Bean methods.
๐Ÿ“š@PropertySource("classpath:config.properties") - Loads custom property files.
๐Ÿงช@Profile("dev") - Activates bean/class for specific profile (e.g., dev).

๐Ÿง  Powered by Passion, Compiled with Precision

© 2025 JavaVerse Blog — Crafted by Janki Patel

๐Ÿ’ป All things Java • Tutorials • Insights • Best Practices

Comments

Popular posts from this blog

๐Ÿ”ฅ Java Exception and Error Handling

Understanding How OOP Concepts Work with Real-Life Examples

๐ŸŒฟ⚙️ Spring Boot Simplified