목록Spring (72)
똑같은 삽질은 2번 하지 말자
잘 정리된 PDF파일이 있어서 작성 안할려고 했는데, 뭔가 문서화를 내 손으로 안하면 찜찜해서 조금이라도 적어보려고 한다. 이번 강의에서는 REST API를 개발할 때, 성능최적화를 하는 방법들에 대해서 인데, 제일 중요한건 엔티티를 웹에 노출해서는 안된다! 솔직히 이 한마디로 이번 강의 전체가 들어 있다고 보면 될꺼같다.. 그럼 어떻게 해야하나? 간단하다. 별도의 DTO를 만들어서 거기서 조회한 엔티티를 넣어서 반환해 주면 된다. ex) // 조회 API @GetMapping("/api/v2/members") public Result membersV2() { ListfindMembers = memberService.findMembers(); Listcollect = findMembers.stream()..
주로 Rest API를 처리할 때, 많이 쓰이고 밑의 코드와 같이 구분자로 구별한다. 최근 동향은 죄다 API API이니깐 잘 알아두고 써먹자! 참고로, Spring에서는 이러한 전달인자를 처리하는데 두 가지 방법을 제공하는데, 또 다른 방법으로는 @RequestParam 이 있다는거~ @PutMapping("/api/v2/members/{id}") public UpdateMemberResponse updateMemberV2(@PathVariable("id") Long id, @RequestBody @Valid UpdateMemberRequest request) { memberService.update(id,request.getName()); Member findMember = memberService...
콘솔창을 킨뒤 본인이 다운한 이클립스 폴더를 찾아서 디렉토리 이동을 해준다. 그리고 eclipse -clean -clearPersistedState 명령어를 쳐주고 기다린다~
git rebase {branch_name} : 해당 브랜치를 base로 한다. git rebase --continue : conflict 해결하고 계속해서 rebase하기, git rebase --abort : rebase작업취소 git cherry-pick {commit_name} : 다른 branch에서 commit 한개 가져오기 (conflict는 안생기지만 새로운 commit이 생김) git reflog : HEAD 나열 보기 , git result HEAD@{14} --hard : 해당 헤드로 강제이동 git checkout -t origin/{branch_name} : 원격 브랜치를 로컬 브랜치로 바로 가져오기 git branch {branch_name} : 브랜치 생성하기 git branc..
Spring Boot는 애플리케이션 운영환경에서 유용한 기능을 제공한다. 제공하는 기능중 엔드포인트와 매트릭스 그리고 데이터를 활용하는 모니터링 기능에 대해 알아보자. Actuator https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints Spring Boot Reference Documentation docs.spring.io JConsole 사용하기 https://docs.oracle.com/javase/tutorial/jmx/mbeans/ https://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html V..
Spring RestClient RestTemplate Blocking I/O 기반의 Synchronous API RestTemplateAutoConfiguration 프로젝트에 spring-web 모듈이 있다면 RestTemplateBuilder를 빈으로 등록해 줍니다. https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#rest-client-access Integration As a lightweight container, Spring is often considered an EJB replacement. We do believe that for many, if not most, applicatio..
페이지가 두개있다. hello.html , my.html my페이지는 로그인 한 사용자에게만 접근 가능하게 하고 싶다. Spring Security를 이용해서 해보자. org.springframework.boot spring-boot-starter-security 추가해서 테스트를 돌려보면 @RunWith(SpringRunner.class) @WebMvcTest(HomeController.class) public class HomeControllerTest { @Autowired MockMvc mockMvc; @Test public void hello() throws Exception{ mockMvc.perform(get("/hello")) .andDo(print()) .andExpect(status()..
데이터베이스 초기화 테스트를 할때 @SpringBootTest 를 이용하면 test용의 properties가 없으면 전 범위 스코프에서 다 따오기 때문에 더 느릴수 있다는거 인지하자. (DataJpaTest는 슬라이스 테스트로써 Embedded DB만 설정해주면 빠르게 동작) JPA를 사용한 데이터베이스 초기화 spring.jpa.hibernate.ddl-auto spring.jpa.generate-dll=true로 설정 해줘야 동작함. SQL 스크립트를 사용한 데이터베이스 초기화 schema.sql 또는 schema-${platform}.sql data.sql 또는 data-${platform}.sql ${platform} 값은 spring.datasource.platform 으로 설정 가능. reso..
Spring Data JPA JPA은 ORM을 위한 자바 EE 표준이며 Spring-Data-JPA는 JPA를 쉽게 사용하기 위해 스프링에서 제공하고 있는 프레임워크이다. 추상화 정도는 Spring-Data-JPA -> Hibernate -> JPA 이다. Hibernate를 쓰는 것과 Spring Data JPA를 쓰는 것 사이에는 큰 차이가 없지만 구현체 교체의 용이성 저장소 교체의 용이성 이라는 이유에서 Spring Data JPA를 사용하는것이 더 좋다. 자바의 Redis클라이언트가 Jdis에서 Lettuce로 대세가 넘어갈 때 Spring Data Redis를 사용하면 아주 쉽게 교체가 가능했다. Spring Data JPA, Spring Data MongoDB, Spring Data Redis..
SpringBoot가 지원하는 Spring Data 연동기술 SQL DB NoSQL 인메모리 데이터베이스 지원 DataSource 설정 DBCP 설정 JDBC 사용하기 스프링 데이터 JPA 사용하기 jOOQ 사용하기 데이터베이스 초기화 데이터베이스 마이그레이션 툴 연동하기 Redis (Key/Value) MongoDB (Document) Neo4J (Graph) Gemfire (IMDG) Solr (Search) Elasticsearch (Search & Analytics) Cassandra Couchbase LDAP InfluxDB H2 스프링부트가 지원하는 인메모리 DataBase:H2 우리가 H2에대한 아무런 설정을 하지않으면 자동으로 인메모리데이터베이스로 설정된다. Spring-JDBC가 clas..