본문 바로가기

Spring

(14)
@SpringBootApplication 김영한 강사님의 강의를 보며 따라하던 중에 SpringBootApplication 어노테이션이 궁금해서 찾아보았다. CoreApplication쪽에 사용되는 @SpringBootApplication @SpringBootApplication은 meta-annotaion이라고 부르고 @SpringBootApplication 내부를 보면 @SpringBootConfiguration, @EnableAutoConfiguration, @ComponentScan 이 결합이 되어있습니다. Spring Boot의 빈 등록 방식은 2 단계를 걸쳐서 등록합니다. 1. ComponentScan으로 본인 패키지 기준 본인 패키지 및 하위 패키지 @Component라는 어노테이션이 붙은 class(@Component, @Con..
섹션 1. 객체 지향 설계와 스프링 스프링의 생태계 필수 스프링 프레임워크(https://spring.io/projects/spring-framework) 스프링 부트(https://spring.io/projects/spring-boot) 선택 스프링 데이터(https://spring.io/projects/spring-data/) 스프링 세션(https://spring.io/projects/spring-session) 스프링 시큐리티(https://spring.io/projects/spring-security) 스프링 Rest Docs(https://spring.io/projects/spring-restdocs) 스프링 배치(https://spring.io/projects/spring-batch) 스프링 클라우드(https://spring..
6장 AOP 1/2 스프링에서 적용된 AOP는 선언적 트랜잭션 기능 1. 트랜잭션 코드의 분리 문제 비즈니스 로직이 주인이어야 할 메소드 안에 트랜잭션코드가 더 많은 자리를 차지 메소드 분리 UserService.class public void upgradeLevels() throws Exception { // 트랜잭션 경계설정(트랜잭션 시작부분) TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition()); try { //비지니스 로직 List users = userDao.getAll(); for (User user : users) { if (canUpgradeLevel(user)) { this.upg..
4장 예외 1. 사라진 SQLException JdbcTemplate 적용 전 public void deleteAll() throws SQLException { this.jdbcTemplate.update("delete from users"); } JdbcTemplate 적용 후 public void deleteAll() { this.jdbcTemplate.update("delete from users"); } 초난감 예외처리 대표 유형 예외 블랙홀 catch 부분에서 해결하지 않고 그냥 넘어 가버리는 것 문제 1 try{ ... } catch(SQLException e) { } 문제 2 try{...} catch (SQLException e){ System.out.println(e); } 문제 3 try{...}..
3장 템플릿 템플릿이란? 바뀌는 성질이 다른 코드 중에서 변경이 거의 일어나지 않으며 일정한 패턴으로 유지되는 특성을 가진 부분을 자유롭게 변경되는 성질을 가진 부분으로부터 독립시켜서 효과적으로 활용할 수 있도록 하는 방법 문제 기존 소스는 예외가 발생했을 경우 리소스 사용한 리소스를 반환 X DB커넥션은 리소스를 공유해 사용할 때 예외가 발생했을 경우 예외처리를 이용해 사용한 리소스를 반환을 해야한다. public void deleteAll() throws SQLException { Connection c = dataSource.getConnection();// 공유 리소스 부분 PreparedStatement ps = c.prepareStatement("delete from users"); // 공유 리소스 부분..
2장 테스트 JUnit이란자바 프로그래밍 언어용 유닛 테스트 프레임워크JUnit 5 구조JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage JUnit Platfom : JVM에서 테스트 프레임워크를 시작하기 위한 기반 역할JUnit Jupiter : 테스트들을 작성하기 위한 새로운 프로그래밍과 확장 모델의 조합JUnit Vintage : JUnit 5 플랫폼 상에서 JUnit 3과 JUnit 4 기반의 테스트들이 구동되는 것을 지원JUnit 동작 방식1. 테스트 클래스에서 @Test가 붙은 public이고 void형이며 파라미터가 없는 테스트 메서드를 모두 찾는다.2. 테스트 클래스의 오브젝트를 하나 만든다com.example.demo.UserDaoTest@1fc2b..