분류 전체보기 562

[SpringBoot]스프링 빈 등록:2.자바코드

※ 이전 편 : 2025.01.06 - [🍃 Spring/🍃 Spring Boot] - [SpringBoot]스프링 빈 등록:1.컴포넌트 스캔과 자동 의존관계 설정  자바코드를 적어 스프링 빈을 등록해보자. 서비스와 리포지토리의 @Service @Repository @Autowired 어노테이션을 모두 지워준다.main에 SpringConfig클래스를 만든다.SpringConfig 코드@Configuration 어노테이션을 클래스 위에 적는다.@Bean 어노테이션을 서비스와 리포지토리 메서드에 적어준다.컨트롤러는 그대로 어노테이션 @Controller와 @Autowired가 필요하다. config 전체코드더보기package hello.hellospring;import org.springframewor..

[SpringBoot]스프링 빈 등록:1.컴포넌트 스캔과 자동 의존관계 설정

Spring Cotainer 🏭  스프링이 시작될 때 스프링 컨테이너 🏭 라는 통이 생긴다. 스프링 컨테이너에 클래스를 등록해야 하는데, 이 때 사용되는 게 스프링 빈🥔 이다.💡 스프링 빈을 등록하는 두가지 방법컴포넌트 스캔과 자동 의존관계 설정.자바 코드로 직접 스프링 등록하기.먼저 1번 방법을 알아보자.   @Component   이때 @Controller @ Service @Repository 가 붙은 클래스 객체를 스프링에 담아 관리한다.이것을 스프링 빈이 관리한다 고 한다.사실 이 어노테이테이션들은 컴포넌트 @Component 를 이용해 만들어졌다. 스프링이 이 컴포넌트들을 객체로 하나씩 만들어 스프링 컨테이너에 등록한다.컴포넌트 스캔이 완료되었다.  @Autowired: Controll..

[SpringBoot][JUnit]회원관리-서비스와 테스트

이전 편 : 2025.01.04 - [🍃 Spring/🍃 Spring Boot] - [SpringBoot]회원관리-도메인과 리포지토리 그리고 테스트  @Service 폴더 src-main-java-hello-hellspring에서 service패키지의 MemberService 클래스.클래스 위에 @Service를 적어준다.서비스 코딩코드전체코드더보기package hello.hellospring.service;import java.util.List;import java.util.Optional;import org.springframework.stereotype.Service;import hello.hellospring.domain.Member;import hello.hellospring.reposito..

[SpringBoot][JUnit]회원관리-도메인과 리포지토리 그리고 테스트

Domain & @Repository @Repository 를 레포지토리 클래스 위에 붙여줍니다.private static Map store : save()시 저장할 데이터용으로 사용합니다.private static long sequence : 0, 1, 2...식으로 카운트를 세는 시퀀스 그 자체.save() : 멤버 저장용.findId() : id로 멤버가 있는 지 확인하는데, null이면 Optional을 반환합니다.findByName()store.values().stream() : store 맵의 값들만 불러와 Stream을 만든 뒤.filter(member -> member.getName().equals(name)) : 일치하는 이름이 일치하는 것들을 찾습니다..findAny(); : 일치하는 ..

[SpringBoot]회원관리-비지니스 요구사항 정리

비지니스 요구사항 정리 데이터 : 회원ID, 이름기능 : 회원 등록, 조회아직 데이터 저장소가 선정되지 않음(가상의 시나리오)→ 저장소가 지정되지 않았기 때문에 Repository를 interface로 만들어 진핸한다.  일반적인 웹 애플리케이션 계층 구조  컨트롤러웹 MVC의 컨트롤러 역할.java단의 진입단계.서비스핵심 비즈니스 로직 구현.ex) 중복가입 불가능하게 만든다든지.리포지토리DB에 접근.도메인 객체를 DB에 저장하고 관리.도메인비지니스 도메인 객체.※ DTO랑 비슷하지만 도메인은 비지니스 로직을 가진다는 점이 다르다.ex) 회원, 주문, 쿠폰 등을 DB에 저장하고 관리.※ 참조 : https://www.inflearn.com/roadmaps/373

[SpringBoot]웹 개발 기초-API @ResponseBody

※ 이전 편 : 2025.01.03 - [🍃 Spring/🍃 Spring Boot] - [SpringBoot]웹 개발 기초-MVC와 템플릿 엔진  @ResponseBody: html의 Body란에 그대로 data를 반환한다.    주로 객체를 return해 json데이터를 반환하기 위해 많이 사용된다. Controller단에 메서드를 만들었다.code더보기package hello.hellospring.Controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.GetMapping;import org.sprin..

[SpringBoot][Thymeleaf]웹 개발 기초-MVC와 템플릿 엔진

💡 MVC patternModel, View, Controller데이터, 화면, 자바코드를 분리한 것이다.  코드 templates폴더에 html파일 하나를 만들었습니다.더보기 hello! templateController폴더에 HelloController라는 자바파일에 helloMvc라는 메서드를 만듭니다.더보기package hello.hellospring.Controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.an..

[SpringBoot]웹 개발 기초-정적 컨텐츠

웹 개발에는 세가지 종류가 있다.정적 컨텐츠MVC와 템플릿 엔진API  정적 컨텐츠Static Content  static폴더에 hello-static.html이란 파일을 만들었습니다.이런 화면입니다.더보기 정적 컨텐츠입니다.스프링 부트는 자바 코드가 들어가지 않은 이 정적컨텐츠를 이렇게 처리합니다.웹브라우저에서 주소 http://localhost:8080/hello-static.html 적으면 request가 내장된 톰캣서버로 갑니다.톰캣은 스프링부트 안 스프링 컨테이너에서 hello-static관련 컨트롤러가 있는 지 검색합니다.관련 컨텐츠가 없기에, resouces-static폴더에서 찾습니다.발견된 정적 컨텐츠인 hello-static.html을 웹브라우저로 response합니다.🌟 관련 ..

반응형