From 8ce36aa09a1bb9c31fa5e5e14fdedbea9cbf6fe0 Mon Sep 17 00:00:00 2001
From: galcyurio
이 문서의 원본은 xdoc포맷이며 프로젝트의 Git에서 찾을 수 있다. - 저장소를 포크입니다, 를 업데이트합니다, 그리고 풀 요청을 보냅니다. + repository 를 fork 하고, 업데이트하고 pull request 를 보내주십시오.
당신처럼 이 문서를 읽는 사람들에게 이 문서의 최고의 저자가 될수 있다!
From e583d8b510592265f0a6f0bfe7316041982e429e Mon Sep 17 00:00:00 2001 From: galcyurio이 장은 마이바티스 스프링 연동모듈을 설치하고 셋팅하는 방법에 대해 간단히 보여준다. 그리고 트랜잭션을 사용하는 간단한 애플리케이션을 만드는 방법까지 다룰 것이다.
-마이바티스 스프링 연동모듈을 사용하기 위해서, 클래스패스에 mybatis-spring-${project.version}.jar를 포함시켜야 한다.
메이븐을 사용하고 있다면 pom.xml에 다음처럼 의존성을 추가하면 된다.
마이바티스를 스프링과 함께 사용하려면 스프링의 애플리케이션 컨텍스트에 적어도 두개를 정의해줄 필요가 있다.
두가지는 SqlSessionFactory와 한개 이상의 매퍼 인터페이스이다.
DataAccessException예외가 발생한다.
- If you use the Java Configuration: + 자바로 설정하면 다음과 같다.
마이바티스만 사용하면, SqlSessionFactory는 SqlSessionFactoryBuilder를 사용해서 생성한다.
마이바티스 스프링 연동모듈에서는, SqlSessionFactoryBean가 대신 사용된다.
팩토리 빈을 생성하기 위해, 스프링 XML설정파일에 다음설정을 추가하자.
MapperFactoryBean나 SqlSessionDaoSupport를 확장하는 다른 DAO에 주입될것이다.
SqlSessionFactory는 JDBC DataSource의 필수 프로퍼티가 필요하다.
어떤 DataSource라도 상관없고 다른 스프링 데이터베이스 연결처럼 설정되어야만 한다.
설정파일이 마이바티스 설정을 완전히 다룰 필요는 없다.
어떤 환경, 어떤 데이터소스 그리고 마이바티스 트랜잭션 관리자가 무시될수도 있다.
- SqlSessionFactoryBean creates its own, custom MyBatis Environment with these values set as required.
SqlSessionFactoryBean 는 필요에 따라 이 값들을 설정하여 자체적인 MyBatis Environment 를 만든다.
설정파일이 필요한 다른 이유는 마이바티스 XML파일이 매퍼 클래스와 동일한 클래스패스에 있지 않은 경우이다. 이 설정을 사용하면 두가지 옵션이 있다. @@ -89,7 +89,7 @@ public SqlSessionFactory sqlSessionFactory() { 이에 관련해서는 트랜잭션을 다루는 장에서 볼수 있다.
- In case you are using the multi-db feature you will need to set the databaseIdProvider property:
+ 만약 multi-db 기능을 사용한다면 다음과 같이 databaseIdProvider 속성을 설정해야 한다.
configuration property has been added.
- It can be specified a Configuration instance directly without MyBatis XML configuration file.
- For example:
+ 1.3.0 버전 부터 configuration 속성이 추가되었다.
+ 다음과 같이 MyBatis XML 설정 파일없이 Configuration 인스턴스를 직접 지정할 수 있습니다.
마이바티스 스프링 연동모듈은 한번 셋업되면 트랜잭션을 투명하게 관리한다. DAO클래스에 어떠한 추가적인 코드를 넣을 필요가 없다.
-스프링 트랜잭션을 가능하게 하려면, 스프링 설정파일에 DataSourceTransactionManager를 생성하자.
이 코드는 매퍼를 사용하지만 SqlSession를 사용해서 잘 동작할 것이다.
이 코드는 매퍼를 사용하지만 SqlSession를 사용해도 잘 동작한다.
마이바티스에서는 데이터 접근 객체인 DAO를 만든것보다 직접 SqlSession를 생성하기 위해 SqlSessionFactory를 사용한다.
세션을 한번 생성하면 매핑구문을 실행하거나 커밋 또는 롤백을 하기 위해 세션을 사용할수 있다.
마지막으로 더 이상 필요하지 않은 상태가 되면 세션을 닫는다.
From 4792d0dbace95013a119fa808887f4a422e1e5f8 Mon Sep 17 00:00:00 2001
From: galcyurio SqlSessionDaoSupport 나 SqlSessionTemplate 를 사용하자.
마이바티스 스프링 연동모듈은 다른 빈에 직접 주입할 수 있는 쓰레드에 안전한 매퍼를 생성할 수 있다.
매퍼를 등록하는 방법은 기존의 전통적인 XML설정법을 사용하거나 새로운 3.0 이후의 자바설정(일명 @Configuration)을 사용하느냐에 따라 다르다.
SqlSessionTemplate 를 사용해야만 한다.
하나씩 매퍼를 모두 등록할 필요가 없다. 대신 클래스패스를 지정해서 마이바티스 스프링 연동모듈의 자동스캔기능을 사용할 수 있다.
From 5201e9f140da4d6c7b2270cdd9f7a81c5c0dbedf Mon Sep 17 00:00:00 2001 From: galcyurio- Please see the MyBatis Spring-boot-stater - subproject docs for details. + 자세한 내용은 MyBatis Spring-boot-stater + 하위 프로젝트 문서를 참조하십시오.
마이바티스 스프링 연동모듈을 사용해더라도 마이바티스 API를 직접 사용할 수 있다.
SqlSessionFactoryBean을 사용해서 스프링에서 SqlSessionFactory를 생성하고 팩토리를 사용하자.
마이바티스 스프링 연동모듈을 사용해더라도 마이바티스 API를 직접 사용할 수 있다.
- SqlSessionFactoryBean을 사용해서 스프링에서 SqlSessionFactory를 생성하고 팩토리를 사용하자.
MyBatis-Spring 연동 모듈을 사용해도 계속해서 MyBatis API를 직접 사용할 수 있다.
+ SqlSessionFactoryBean을 사용해서 스프링에서 SqlSessionFactory를 생성하고 팩토리를 사용하면 된다.
이 방법은 신중히 사용하자. 왜냐하면 잘못사용하면 런타임 에러나 데이터 문제등을 야기할수 있기 때문이다. +
이 방법은 신중히 사용하자. 왜냐하면 잘못사용하면 런타임 에러나 데이터 문제등을 야기할수 있기 때문이다. API를 직접 사용할때는 다음의 규칙들에 유의해야 한다.
스프링 트랜잭션에 속할지 않고 별도의 트랜잭션에서 동작한다.
+스프링 트랜잭션에 속하지 않고 별도의 트랜잭션에서 동작한다.
SqlSession이 스프링 트랜잭션 관리자가 사용하는 DataSource를 사용하고
- 이미 트랜잭션이 동작하고 있다면 이 코드는 예외를 발생시킬것이다.
마이바티스의 DefaultSqlSession은 쓰레드에 안전하지 않다.
- 빈에 이 객체를 주입하면 아마도 에러를 발생시킬수있다.
DefaultSqlSession을 사용해서 생성한 매퍼 또한 쓰레드에 안전하지 않다.
- 이렇게 만든 매퍼를 빈에 주입하면 에러를 발생시킬수있다.
SqlSession은 항상 마지막에 닫아주는 것을 확인해야 한다.
SqlSession은 항상 마지막에 close() 메서드를 호출해야 한다.
마이바티스 스프링 연동모듈의 1.1.0버전에서는 스프링 배치 애플리케이션을 만들기 위해 두개의 빈을 제공한다.
두개의 빈은 MyBatisPagingItemReader 와 MyBatisCursorItemReader 와 MyBatisBatchItemWriter이다.
- Also, As of version 2.0.0 provides three builder classes for supporting the Java Configuration: the MyBatisPagingItemReaderBuilder,
- the MyBatisCursorItemReaderBuilder and the MyBatisBatchItemWriterBuilder.
+
+ 또한 2.0.0 버전에서는 Java Configuration 을 지원하는 다음의 세 가지 Builder class 를 제공한다.
+ MyBatisPagingItemReaderBuilder, MyBatisCursorItemReaderBuilder 그리고 MyBatisBatchItemWriterBuilder 이다.
중요 이 문서는 스프링 배치에 대한 것으로
@@ -140,31 +141,28 @@ public Map
- This bean is an
- NOTE To use this bean you need at least MyBatis 3.4.0 or a newer version.
+ 중요 이 빈을 사용하려면 최소한 MyBatis 3.4.0 이나 그 이상이어야 한다.
- It executes the query specified as the
- The reader will use a separate connection so the select statement does no participate in any transactions created
- as part of the step processing.
+ reader 는 별도의 connection 을 사용하므로 select 문은 step processing 일부로 생성된 트랜잭션에 속하지 않는다.
When using the cursor you can just execute a regular query: cursor 를 사용할 때 다음과 같이 일반 쿼리를 실행할 수 있다. Follows below a sample configuration snippet: 아래는 샘플 설정이다.
- NOTE
- See JPetstore 6 demo to know about how to use Spring with a full web application server.
+ 중요
+ 전체 웹 애플리케이션 서버에서 Spring을 사용하는 방법을 알고 싶다면 JPetstore 6 demo 를 참조하십시오.
- You can check out sample code from the MyBatis-Spring repo:
+ MyBatis-Spring repository 에서 샘플 코드를 확인할 수 있다.
- Any of the samples can be run with JUnit 5.
+ 모든 샘플은 JUnit5 에서 실행할 수 있다.
- The sample code shows a typical design where a transactional service gets domain objects from a data access layer.
+ 샘플 코드는 트랜잭션 서비스가 data access layer 에서 도메인 개체를 가져 오는 일반적인 디자인을 보여준다.
-
- It is a transactional bean, so a transaction is started when any of its methods is called
- and committed when the method ends without throwing an unchecked exception.
- Notice that transactional behaviour is configured with the
-
- This service calls a data access layer built with MyBatis. This layer
- consists on a just an interface
- Note that, for the sake of simplicity we used the interface
- We will see different ways to find the mapper interface, register it to Spring and inject it into the service bean:
+ 매퍼 인터페이스를 찾고 Spring에 등록하고 서비스 빈에 주입하는 여러 가지 방법을 살펴본다.
- Please take a look at the different
- Este bean es un
@@ -155,7 +155,7 @@ public Map
- Este bean es un
diff --git a/src/site/ja/xdoc/batch.xml b/src/site/ja/xdoc/batch.xml
index 4003c31337..28ee1b0461 100644
--- a/src/site/ja/xdoc/batch.xml
+++ b/src/site/ja/xdoc/batch.xml
@@ -142,7 +142,7 @@ public Map
- This bean is an
diff --git a/src/site/ko/xdoc/batch.xml b/src/site/ko/xdoc/batch.xml
index a3f0d85865..b1c0414fc5 100644
--- a/src/site/ko/xdoc/batch.xml
+++ b/src/site/ko/xdoc/batch.xml
@@ -40,7 +40,7 @@
마이바티스 배치 SqlSession을 다루지는 않는다. 배치 세션에 대해서는 SqlSession 사용에서 좀더 다루었다. 이 빈은 마이바티스로 페이지를 처리하는 형태로 데이터베이스 데이터를 읽어오는 이 빈은 마이바티스로 페이지를 처리하는 형태로 데이터베이스 데이터를 읽어오는 요청된 데이터를 가져오기 위해
- 이 빈은 cursor 를 사용하여 데이터베이스에서 레코드를 읽는
diff --git a/src/site/xdoc/batch.xml b/src/site/xdoc/batch.xml
index 36a7edf164..507f4c9ae1 100644
--- a/src/site/xdoc/batch.xml
+++ b/src/site/xdoc/batch.xml
@@ -41,7 +41,7 @@
- This bean is an
@@ -153,7 +153,7 @@ public Map
- This bean is an
diff --git a/src/site/zh/xdoc/batch.xml b/src/site/zh/xdoc/batch.xml
index b555063bbd..ca405d5d7c 100644
--- a/src/site/zh/xdoc/batch.xml
+++ b/src/site/zh/xdoc/batch.xml
@@ -41,7 +41,7 @@
- This bean is an
@@ -154,7 +154,7 @@ public Map
- This bean is an
IteamReader that reads records from a database using a cursor.
+ 이 빈은 cursor 를 사용하여 데이터베이스에서 레코드를 읽는 IteamReader 이다.
setQueryId property to retrieve requested data
- by using the method selectCursor().
- Each time a read() method is called it will return the next element of the cursor until no more
- elements are left.
+ setQueryId 속성으로 지정된 쿼리를 실행하여 selectCursor() 메서드를 사용하여 요청 된 데이터를 검색한다.
+ read() 메서드가 호출 될 때마다 요소가 더 이상 남아 있지 않을 때까지 cursor 의 다음 요소를 반환한다.
FooService.java acts as the service:
+ 다음 FooService.java 는 서비스처럼 작동한다.
@Transactional
- attribute. This is not required; any other way provided by Spring can be used to demarcate
- your transactions.
+ 이것은 트랜잭션 빈이다. 따라서 어떤 메서드든 실행이 되면 트랜잭션이 시작되고 예외가 발생하지 않았을 때 커밋된다.
+ 트랜잭션은 @Transactional annotation 을 통해 설정할 수 있다.
+ 이것은 필수가 아니다. Spring이 제공하는 다른 방법을 사용하여 트랜잭션을 구분할 수 있다.
UserMapper.java
- that will be used with a dynamic proxy built by MyBatis at
- runtime and injected into the service by Spring.
+ 이 서비스는 MyBatis로 이루어진 DAO layer 를 호출한다.
+ 이 layer는 런타임시 MyBatis에 의해 작성되고 Spring에 의해 서비스에 주입되는 동적 프록시와 함께 사용되는 UserMapper.java 인터페이스로 구성된다.
UserMapper.java for the DAO scenario
- where a DAO is built with an interface and a implementation though in this case it would have been more
- adequate to use an interface called UserDao.java instead.
+ 단순함을 위해서 DAO가 인터페이스와 그 구현체로 만들어진 DAO 시나리오를 위해 UserMapper.java 인터페이스를 사용했지만,
+ 이 경우 대신 UserDao.java라는 인터페이스를 사용하는 것이 더 적절하다.
-
-
@@ -103,8 +97,7 @@ public interface UserMapper {
Sample test
- Description
+ 샘플 테스트
+ 설명
SampleMapperTest.java
- Shows you the base configuration based on a
MapperFactoryBean
- that will dynamically build an implementation for UserMapper
+ UserMapper 구현체를 동적으로 빌드 할 MapperFactoryBean에 기반한 기본 구성을 보여준다.
@@ -112,7 +105,7 @@ public interface UserMapper {
SampleScannerTest.java
- Shows how to use the
MapperScannerConfigurer so all the mappers in a project are autodiscovered.
+ MapperScannerConfigurer 를 사용하여 어떻게 프로젝트의 모든 매퍼들을 자동으로 검색되도록 하는 방법을 보여준다.
@@ -120,8 +113,7 @@ public interface UserMapper {
SampleSqlSessionTest.java
- Shows how to hand code a DAO using a Spring managed
SqlSession
- and providing your own implementation UserDaoImpl.java.
+ Spring에서 관리하는 SqlSession을 사용하여 DAO를 코딩하고 자체적인 구현체인 UserDaoImpl.java 를 제공하는 방법을 보여준다.
@@ -129,8 +121,7 @@ public interface UserMapper {
SampleEnableTest
- Shows how to use Spring's
@Configuration with the @MapperScann annotation so
- mappers are autodiscovered.
+ 스프링의 @Configuration과 @MapperScann annotation을 함께 사용하여 매퍼를 자동으로 검색하는 방법을 보여준다.
@@ -138,7 +129,7 @@ public interface UserMapper {
SampleNamespaceTest
- Shows how to use the custom MyBatis XML namespace.
+ 커스텀 MyBatis XML 네임스페이스를 사용하는 방법을 보여준다.
@@ -146,7 +137,7 @@ public interface UserMapper {
SampleJavaConfigTest.java
- Shows how to use Spring's
@Configuration to create MyBatis beans manually.
+ 스프링의 @Configuration을 사용하여 MyBatis 빈들을 수동적으로 생성하는 방법을 보여준다.
@@ -154,7 +145,7 @@ public interface UserMapper {
SampleJobJavaConfigTest.java
- Shows how to use
ItemReader and ItemWriter on Spring Batch using Java Configuration.
+ Java Configuration을 이용하여 Spring Batch에서 어떻게 ItemReader과 ItemWriter를 사용하는지 보여준다.
@@ -162,13 +153,13 @@ public interface UserMapper {
SampleJobXmlConfigTest.java
- Shows how to use
ItemReader and ItemWriter on Spring Batch using XML Configuration.
+ XML Configuration을 이용하여 Spring Batch에서 어떻게 ItemReader과 ItemWriter를 사용하는지 보여준다.
applicationContext.xml files to see MyBatis-Spring in action.
+ MyBatis-Spring이 실제로 어떻게 다르게 작동하는지 보려면 applicationContext.xml 파일을 살펴보십시오.
IteamReader que lee registros de una base de datos usando paginación.
+ Este bean es un ItemReader que lee registros de una base de datos usando paginación.
IteamReader que lee registros de la base de datos usando un cursor.
+ Este bean es un ItemReader que lee registros de la base de datos usando un cursor.
IteamReader that reads records from a database using a cursor.
+ This bean is an ItemReader that reads records from a database using a cursor.
IteamReader이다. ItemReader이다. setQueryId 프로퍼티에 명시된 쿼리를 실행한다.
쿼리는 setPageSize 프로퍼티에 명시된 크기만큼 데이터를 가져오도록 실행된다.
@@ -141,7 +141,7 @@ public MapIteamReader 이다.
+ 이 빈은 cursor 를 사용하여 데이터베이스에서 레코드를 읽는 ItemReader 이다.
IteamReader that reads records from a database in a paging fashion.
+ This bean is an ItemReader that reads records from a database in a paging fashion.
IteamReader that reads records from a database using a cursor.
+ This bean is an ItemReader that reads records from a database using a cursor.
IteamReader that reads records from a database in a paging fashion.
+ This bean is an ItemReader that reads records from a database in a paging fashion.
IteamReader that reads records from a database using a cursor.
+ This bean is an ItemReader that reads records from a database using a cursor.