본문 바로가기

spring

(5)
[Spring] Mybatis와 JpaRepository 인터페이스 하나의 repository로 관리하기 TestSample(entity)객체 와 같은 디렉토리에 TestSampleRepository 생성 extends JpaRepository, TestSampleRepositoryCustom(네이밍 꼭 맞춰야함) 추가 @Repository public interface TestSampleRepository extends JpaRepository, TestSampleRepositoryCustom { } TestSampleRepositoryCustom 인터페이스 생성, 사용할 메소드명 및 파라미터 지정 public interface TestSampleRepositoryCustom { TestSample test() { } } TestSampleRepositoryImpl 클래스 생성 후 implements Te..
[Spring] 간단한 TestCase 만들기 사전 작업 : [Spring] Controller와 Service 생성하기 테스트 진행을 위하여 다음과 같이 작업합니다. implementation 'junit:junit:4.12' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureMockMvc public class TestTableTest { @Autowired private MockMvc mockMv..
[Spring] Controller와 Service 생성하기 사전 작업 : [Spring] 다중 데이터소스 설정(Multiple Datasource JPA, Mybatis) Mybatis 를 위한 mapper SELECT * FROM test_table import com.cafe24.cmc.domain.test.TestTable; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Map; @Repository public interface TestMapper { Map getAll() throws Exception; } JPA를 위한 Entity, Repository import lombok.Data; import lombok.NoArgsConstruc..
[Spring] Spring JPA 시작하기(기본 설정 값, JPA 객체 생성) 현재까지는 스프링 부트를 사용하면서 DB 관리를 위하여 마이바티스를 사용하고 있었다. 그러나 반복적인 코드 작성으로 인한 시간 소모가 생각보다 크다는 것을 알게 되었고 이를 소폭이라도 감소시키기 위하여 JPA를 사용하기로 하였다. 역시나 스프링이 지원해주는 스프링 JPA를 사용하여 빠른 개발을 해보자. 어플리케이션에 JPA 셋팅 의존성 관리 // 스프링MVC를 위한 Spring boot starter 패키지 implementation 'org.springframework.boot:spring-boot-starter-web' // 스프링JPA를 위한 패키지 implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jp..
[Spring Framework] Security 설정 및 원리 스프링 시큐리티 스프링 시큐리티는 필터체인으로 인증과 권한을 확인한다. 따라서 webApplicationContext에 설정을 할 경우 모든 bean이 생성되지 않은 상태에서 로딩이 되므로 에러가 발생한다. rootApplicationContext에 설정하여 우선적으로 bean이 만들어질 수 있도록 해야 한다. 설정방법은 다음과 같다. 파일명 : pom.xml org.springframework.security spring-security-core 4.1.3.RELEASE springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /* config/app/SecurityConf..