๐Ÿ’ป
Albert's Til
GitHub
  • ๋งค์ผ๋งค์ผ ์กฐ๊ธˆ์”ฉ ์„ฑ์žฅํ•˜๊ธฐ
    • README
    • CS
      • Network
      • HTTP
        • NO-CACHE
      • ์˜ค๋ฅ˜ ์ฝ”๋“œ
      • ORM ๋„๊ตฌ
      • Design Pattern
        • CQRS Pattern
          • Event Sourcing and CQRS pattern
        • Builder Pattern
    • DB
      • MySQL
        • Timeline
        • Pagination
        • Index
        • Database Performance Optimization Strategies
        • B+ tree
        • MySQL Connectors VS MySQL Shell(Scripting) VS MySQL Workbench
        • MySQL Storage Engine Architecture
      • Normalization & Denormalization
      • JPA
        • @Transactional
        • Why JPA?
        • About JPA
        • N+1 Issue
        • Index
        • ElementCollection&CollectionTable
        • orphanRemoval
        • CascadeType
        • Use Subselect
        • Dynamic Instance Creation
        • Paging
        • Order
        • Spefication
        • mappedBy
      • MongoDB
        • ObjectId
      • Why MySQL?
      • ACID properties of transactions
      • Between JPA and JDBC
      • Identifiers in Hibernate/JPA
    • Java
      • Jackson de/serialize
      • Collections.singletonList() vs List.of()
      • Manage dependencies in Gradle
      • Logging Level
      • Bean Validation
      • JVM Internals
        • Threads
          • Frame
        • Shared Between Threads
          • Classloader
            • Class Loader Hierarchy
            • Loading Linking Initialization
      • Java Collection Framework
      • Annotation
      • Generic
      • ๋””๋ฏธํ„ฐ ๋ฒ•์น™
    • Spring
      • Caching
      • Spring Integration Overview
        • ThreadPollTaskExecutor
        • Messaging Bridge
        • Channel Adapter
        • Poller
        • Configuration and @EnableIntegration
        • Message Endpoints
        • Message Channels
      • HATEOAS
      • @Autowired vs Constructor Dependency Injection
      • Spring Security
        • JWT ํ† ํฐ ์‚ฌ์šฉํ•œ ์ธ๊ฐ€
        • OAuth 2 Login
        • OAuth 2 ์ธ์ฆ
        • ์ธ๊ฐ€
        • ์ธ์ฆ
        • PasswordEncoder
      • IoC Container
      • Filter,Interceptor,AOP,Argument Resolver
      • Spring Annotation
      • About Spring
    • Kafka
      • Error Channel
    • Infra
      • Scale Up || Scale Out
      • Docker
        • Dockerfile
        • Docker Hub Deploy
        • Command
      • Cloud ์œ ํ˜•
        • Infrastructure as a Service
        • Platform as a Service
        • Software as a Service
      • ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ
        • ์—”์ง„์—‘์Šค(Nginx)
      • ์ฝ”๋“œ ์ž๋™ ๋ฐฐํฌ
        • Technical
      • AWS EC2
        • PEM(Privacy Enhanced Mail) ํ‚ค
      • AWS RDS
      • AWS S3
    • CodeSquad
      • Spring Boot Project 1์ฃผ์ฐจ ํšŒ๊ณ 
      • Spring Boot Project 2์ฃผ์ฐจ ํšŒ๊ณ 
      • Spirng Boot Project 3์ฃผ์ฐจ ํšŒ๊ณ 
      • Spring Boot Project 4์ฃผ์ฐจ ํšŒ๊ณ 
    • Foody Moody ํ”„๋กœ์ ํŠธ
      • Query Performance Comparison
      • HeartCount Asynchronous Issue
      • DeferredResult
      • ResponseBodyEmitter
      • SseEmitter (Spring)
      • Server-Sent Events (SSE)
      • ๊ธฐ์ˆ  ์Šคํƒ ์ ์šฉ ์ด์œ 
      • NO-CACHE(HTTP)
      • Transactional
    • DDD
      • AggregateId
    • Test
      • RestAssured
    • Coding and Algorithmic Problems
      • 819. Most Common Word
      • 344. Reverse String
      • 125. Valid Palindrome
      • 937. Reorder Data in Log Files
    • Node
      • Async... Await...
      • Custom Transactional Decorator Challenger
    • Python
      • Python Basic Grammar
        • Comments and Input/Output
        • Variable
        • Data type
        • Operations and syntax
        • List,Tuple,Dictionary,Set
        • Function
        • Conditional statement
        • Loop
    • HTML
      • HTML Basic
      • HTML Basic Tags
      • HTML Form Tags
      • HTML Table Tags
    • CSS
      • CSS Basic
      • CSS Practice
Powered by GitBook
On this page
  • Bean Annotations
  • @Component
  • @Service
  • @Repository
  • @Component Scanning
  • @Controller
  • @Configuraion
  • Web Annotations
  • @RequestMapping
  • @RequestBody
  • @PathVariable
  • @RequsetParam
  • @ResponseBody
  • @ExceptionHandler
  • @ResponseStatus
  • @RestController
  • @ModelAttribute
  • Core Annotations
  • @Autowired
  • @Bean
  • @Qualifier
  • @Required
  • @Value
  • @DependsOn
  • @Lazy
  • @Lookup
  • @Primary
  • @Scope
  • @Profile
  • @Import
  • @ImportResource
  • @PropertySource
  • @PropertySources

Was this helpful?

  1. ๋งค์ผ๋งค์ผ ์กฐ๊ธˆ์”ฉ ์„ฑ์žฅํ•˜๊ธฐ
  2. Spring

Spring Annotation

Bean Annotations

@Component

  • ๋ชจ๋“  Spring ๊ด€๋ฆฌ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ํ‘œ์‹œํ•œ๋‹ค.

@Service

  • ์„œ๋น„์Šค ๊ณ„์ธต์˜ ํด๋ž˜์Šค๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์—๋…ธํ…Œ์ด์…˜์ž…๋‹ˆ๋‹ค.

  • ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋ณด์œ ํ•˜๊ณ  ์žˆ์Œ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด์„œ ์ž…๋‹ˆ๋‹ค.

@Repository

  • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ €์žฅ์†Œ ์—ญํ• ์„ ํ•˜๋Š” ์ง€์†์„ฑ ๊ณ„์ธต์˜ ํด๋ž˜์Šค์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  • ์—ญํ• ์€ ์ง€์†์„ฑ ๊ด€๋ จ ์˜ˆ์™ธ๋ฅผ ํฌ์ฐฉํ•˜์—ฌ Spring์˜ ํ†ตํ•ฉ๋œ unchecked exceptions๋กœ ๋‹ค์‹œ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@Component Scanning

  • ์Šค์บ”ํ•  annotation configuration ํด๋ž˜์Šค์˜ ํŒจํ‚ค์ง€๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค

  • basePackages ๋˜๋Š” ๊ฐ’ ์ธ์ˆ˜(value๋Š” basePackages์˜ ๋ณ„์นญ) ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ๋ณธ ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ง์ ‘ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@Configuration
@ComponentScan(basePackages = "com.baeldung.annotations")
class VehicleFactoryConfig {}

@Configuration
@ComponentScan(basePackageClasses = VehicleFactoryConfig.class)
class VehicleFactoryConfig {}
  • ์ธ์ˆ˜๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด @ComponentScan annotation ํด๋ž˜์Šค๊ฐ€ ์žˆ๋Š” ๋™์ผํ•œ ํŒจํ‚ค์ง€์—์„œ ์Šค์บ”์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

@Controller

  • Controller ๊ณ„์ธต์˜ ํด๋ž˜์Šค๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์—๋…ธํ…Œ์ด์…˜์ž…๋‹ˆ๋‹ค.

@Configuraion

  • @Bean์ด ๋‹ฌ๋ ค์žˆ๋Š” dean definition ๋ฉ”์„œ๋“œ๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Web Annotations

@RequestMapping

  • @Controller ํด๋ž˜์Šค ๋‚ด๋ถ€์— request handler ๋ฉ”์„œ๋“œ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

    • path, or its aliases, name, and value: which URL the method is mapped to

    • method: compatible HTTP methods

    • params: filters requests based on presence, absence, or value of HTTP parameters

    • headers: filters requests based on presence, absence, or value of HTTP headers

    • consumes: which media types the method can consume in the HTTP request body

    • produces: which media types the method can produce in the HTTP response body

@RequestBody

  • maps the body of the HTTP request to an object:

    • ์—ญ์ง๋ ฌํ™”๋Š” ์ž๋™์ด๋ฉฐ ์š”์ฒญ์˜ ์ฝ˜ํ…์ธ  ์œ ํ˜•์— ๋”ฐ๋ผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

@PathVariable

  • ์ด annotation์€ ๋ฉ”์„œ๋“œ ์ธ์ˆ˜๊ฐ€ URI ํ…œํ”Œ๋ฆฟ ๋ณ€์ˆ˜์— ๋ฐ”์ธ๋”ฉ๋˜์–ด ์žˆ์Œ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

@RequsetParam

  • accessing HTTP request parameters

@ResponseBody

  • Spring์€ ๋ฉ”์†Œ๋“œ์˜ ๊ฒฐ๊ณผ๋ฅผ ์‘๋‹ต์œผ๋กœ ์ทจ๊ธ‰ํ•ฉ๋‹ˆ๋‹ค.

@ExceptionHandler

  • ์ง€์ •๋œ ์˜ˆ์™ธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ง€์ •ํ•œ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๊ธฐ ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@ResponseStatus

  • ์›ํ•˜๋Š” ์‘๋‹ต HTTP ์ƒํƒœ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@RestController

  • combines @Controller and @ResponseBody.

@ModelAttribute

  • ์ด๋ฏธ ๋ชจ๋ธ์— ์žˆ๋Š” ์š”์†Œ์— ์•ก์„ธ์Šค ํ•œ๋‹ค.

Core Annotations

@Autowired

  • Spring์ด ์ฃผ์ž…ํ•  ์˜์กด์„ฑ์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

@Bean

  • @Bean marks a factory method which instantiates a Spring bean

@Qualifier

  • ๋ชจํ˜ธํ•œ ์ƒํ™ฉ์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋Š” bean id ๋˜๋Š” bean ์ด๋ฆ„์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด @Autowired์™€ ํ•จ๊ป˜ @Qualifier๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Required

  • XML์„ ํ†ตํ•ด ์ฑ„์šฐ๋ ค๋Š” ์˜์กด์„ฑ์„ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•œ setter ๋ฉ”์„œ๋“œ์— @Required์„ ์‚ฌ์šฉํ•œ๋‹ค.

@Value

  • ์†์„ฑ ๊ฐ’์„ Bean์— ์ฃผ์ž… ํ•  ์ˆ˜ ์žˆ๋‹ค.

@DependsOn

  • annotation์—์„œ ์„ค์ •ํ•œ bean์„ ๋จผ์ € ์ดˆ๊ธฐํ™” ํ›„ annotation ๋‹ฌ๋ฆฐ bean์„ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.

@Lazy

  • ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ์‹œ๊ฐ€ ์•„๋‹ˆ๋ผ ์š”์ฒญ ์‹œ bean์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@Lookup

  • @Lookup ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ๋ฉ”์†Œ๋“œ๋Š” ํ˜ธ์ถœํ•  ๋•Œ ๋ฉ”์†Œ๋“œ์˜ ๋ฆฌํ„ด ์œ ํ˜• ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฆฌํ„ดํ•˜๋„๋ก Spring์— ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค.

@Component
@Scope("prototype")
public class SchoolNotification {
    // ... prototype-scoped state
}
@Component
public class StudentServices {

    // ... member variables, etc.

    @Lookup
    public SchoolNotification getNotification() {
        return null;
    }

    // ... getters and setters
}

@Primary

  • ๋™์ผํ•œ ์œ ํ˜•์˜ ์—ฌ๋Ÿฌ bean์ค‘ ํŠน์ • bean์„ ์‚ฌ์šฉ์‹œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Scope

  • @Scope๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ @Component ํด๋ž˜์Šค ๋˜๋Š” @Bean ์ •์˜์˜ ๋ฒ”์œ„๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

@Profile

  • ํŠน์ • ํ”„๋กœํ•„์ด ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋งŒ Spring์ด @Component ํด๋ž˜์Šค ๋˜๋Š” @Bean ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๋ ค๋ฉด @Profile๋กœ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@Import

  • ์ด annotation์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์„ฑ component scanning ์—†์ด ํŠน์ • @Configurationํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@ImportResource

  • XML configurations์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@PropertySource

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ค์ •์— ๋Œ€ํ•œ ์†์„ฑ ํŒŒ์ผ์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@PropertySources

  • @PropertySource configurations์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Last updated 2 years ago

Was this helpful?