글

라벨이 spring boot인 게시물 표시

Spring Boot 주요 어노테이션

 ### **📌 Spring Boot에서 꼭 알아야 할 주요 어노테이션 정리!** 🚀 Spring에는 **많은 어노테이션이 있지만, 기본적으로 자주 쓰이는 것들만 먼저 익히면 돼.**\ 💡 **기본적으로 알아야 할 어노테이션은 크게 5가지 카테고리로 정리할 수 있어.** * * * * * **📌 1️⃣ Spring 핵심 어노테이션 (빈 & 의존성 주입)** --------------------------------------- | 어노테이션 | 역할 | | --- | --- | | `@Component` | **Spring 빈(객체)으로 등록** | | `@Service` | **비즈니스 로직을 담당하는 서비스 레이어 등록** (`@Component`와 같은 역할) | | `@Repository` | **데이터베이스와 연결되는 레이어 등록** (예: JPA Repository) | | `@Controller` | **Spring MVC 컨트롤러 등록** (사용자 요청 처리) | | `@RestController` | `@Controller + @ResponseBody` (JSON 응답을 반환하는 컨트롤러) | | `@Autowired` | **Spring이 자동으로 의존성 주입** | 📌 **예제** ``` @Component public class MyComponent {     public void hello() {         System.out.println("Hello from MyComponent!");     } } ``` ``` @Service public class MyService {     private final MyComponent myComponent;     @Autowired  // ✅ 의존성 주입     public MyService(MyComponent myComponen...

Spring 빈(Bean)

 ### **Spring에서 빈(Bean)이란?** **Spring Bean(스프링 빈)**은 **Spring IoC 컨테이너(Bean Container)**가 관리하는 **객체**를 의미합니다.\ 즉, Spring이 자동으로 생성하고 관리하는 인스턴스를 **Bean**이라고 부릅니다. * * * * * **1\. 빈(Bean)이 왜 필요할까?** ------------------------ 자바에서는 객체를 사용할 때 `new` 키워드를 사용하여 직접 생성하는 경우가 많습니다. ``` public class UserService {     private UserRepository userRepository = new UserRepository(); } ``` -   하지만 위처럼 직접 객체를 생성하면 **코드가 하드코딩**되고, -   유지보수가 어렵고, **객체 간의 결합도가 높아지는 문제**가 발생합니다. ✅ **해결책**: Spring의 **빈 컨테이너**를 사용하여 객체를 자동으로 관리!\ Spring에서는 객체를 직접 생성하지 않고, **Spring이 자동으로 생성하고 주입**하도록 설계할 수 있습니다. ``` @Service public class UserService {     private final UserRepository userRepository;     public UserService(UserRepository userRepository) { // 빈을 자동 주입         this.userRepository = userRepository;     } } ``` ➡ **객체 생성을 Spring이 관리하므로, 유지보수가 쉬워지고 결합도가 낮아짐.** * * * * * **2\. 빈(Bean)을 만드는 방법** ----------------------- Spring에서 빈을 등록하는 방...

spring boot 프로젝트 생성시 나오는 리드미

프로젝트 생성시 나오는 리드미인데 읽을거리 있나 싶어서 옮겨둠 # Getting Started ### Reference Documentation For further reference, please consider the following sections: * [Official Gradle documentation](https://docs.gradle.org) * [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.2/gradle-plugin) * [Create an OCI image](https://docs.spring.io/spring-boot/3.4.2/gradle-plugin/packaging-oci-image.html) * [Spring Boot DevTools](https://docs.spring.io/spring-boot/3.4.2/reference/using/devtools.html) * [Spring Web](https://docs.spring.io/spring-boot/3.4.2/reference/web/servlet.html) * [Spring Data JPA](https://docs.spring.io/spring-boot/3.4.2/reference/data/sql.html#data.sql.jpa-and-spring-data) ### Guides The following guides illustrate how to use some features concretely: * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) * [Building REST services with Spring](https:/...

sprint boot 어노테이션

 **Spring Boot**에서 사용하는 **어노테이션(Annotation)**은 **메타데이터** 역할을 하며, 코드에 의미를 부여하고 특정 기능을 활성화하는 데 사용됩니다. Spring에서는 어노테이션을 통해 **의존성 주입**, **요청 처리**, **데이터 매핑** 등의 작업을 간단하게 처리할 수 있습니다. * * * * * **1\. 어노테이션의 역할** ----------------- 어노테이션은 다음과 같은 역할을 합니다: 1.  **구성(Configuration)**:     -   애플리케이션의 동작 방식을 설정합니다.     -   예: `@Configuration`, `@EnableAutoConfiguration` 2.  **의존성 주입(Dependency Injection)**:     -   Spring이 객체를 자동으로 관리하고 주입할 수 있도록 설정합니다.     -   예: `@Autowired`, `@Component` 3.  **웹 요청 처리**:     -   HTTP 요청과 컨트롤러 메서드를 연결합니다.     -   예: `@RestController`, `@GetMapping`, `@PostMapping` 4.  **데이터 매핑**:     -   데이터베이스 테이블과 자바 객체(Entity)를 매핑합니다.     -   예: `@Entity`, `@Table`, `@Column` 5.  **제어 흐름 및 기타 기능**:     -   AOP(Aspect-Oriented Programming)나 트랜잭션 관리를 활성화합니다.     -...

[java] spring 빌드하면 완료 안되고 계속 로딩만 할 때 해결

Execution failed for task ':HelloSpringApplication.main()'. > Build cancelled while executing task ':HelloSpringApplication.main()' * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. 1. preference 들어가서 build tools> gradle에서 build and run using run test using 을 인텔리제이로 바꿔준다 해결 안되면 2. 자바 JDK 다시깔기  https://www.inflearn.com/questions/116973

[spring boot] 빌드하고 종료했더니 에러 Build cancelled while executing task

이미지
Build cancelled while executing task intelliJ에서 preference 들어가서 gradle 검색후 build and run using 이랑 run tests using을 intellij로 바꾸고 인텔리제이 껐다가 켰더니 해결