├── .idea └── misc.xml ├── aop-annotation ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── aop │ │ │ ├── MyFirstAspect.java │ │ │ ├── business │ │ │ │ ├── domain │ │ │ │ │ └── Product.java │ │ │ │ └── service │ │ │ │ │ ├── ProductDao.java │ │ │ │ │ ├── ProductService.java │ │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ │ └── ProductDaoImpl.java │ │ │ └── config │ │ │ └── applicationContext.xml │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── aop-config ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── aop │ │ │ ├── MyFirstAspect.java │ │ │ ├── business │ │ │ │ ├── domain │ │ │ │ │ └── Product.java │ │ │ │ └── service │ │ │ │ │ ├── ProductDao.java │ │ │ │ │ ├── ProductService.java │ │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ │ └── ProductDaoImpl.java │ │ │ └── config │ │ │ └── applicationContext.xml │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── aop-javaconfig ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── aop │ │ │ ├── MyFirstAspect.java │ │ │ ├── business │ │ │ │ ├── domain │ │ │ │ │ └── Product.java │ │ │ │ └── service │ │ │ │ │ ├── ProductDao.java │ │ │ │ │ ├── ProductService.java │ │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ │ └── ProductDaoImpl.java │ │ │ └── config │ │ │ └── AppConfig.java │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── batch-advanced ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── com.springsource.sts.config.flow.prefs │ └── org.eclipse.jdt.core.prefs ├── .springBeans ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ └── business │ │ │ └── domain │ │ │ ├── Member.java │ │ │ └── Product.java │ └── resources │ │ ├── META-INF │ │ ├── jdbc.properties │ │ ├── schema-init-hsqldb.sql │ │ └── spring │ │ │ ├── item-context.xml │ │ │ └── job-context.xml │ │ ├── batch-context.xml │ │ ├── log4j.properties │ │ └── product_csv │ │ └── 1.csv │ ├── site │ └── site.xml │ └── test │ ├── java │ ├── .gitignore │ └── sample.sql │ └── resources │ ├── .gitignore │ └── sample.sql ├── batch-basic ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── com.springsource.sts.config.flow.prefs │ └── org.eclipse.jdt.core.prefs ├── .springBeans ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── batch │ │ │ └── listener │ │ │ │ ├── SampleChunkListener.java │ │ │ │ └── SampleStepExecutionListener.java │ │ │ └── business │ │ │ └── domain │ │ │ └── Product.java │ └── resources │ │ ├── META-INF │ │ ├── jdbc.properties │ │ ├── schema-init-hsqldb.sql │ │ └── spring │ │ │ ├── item-context.xml │ │ │ └── job-context.xml │ │ ├── batch-context.xml │ │ ├── log4j.properties │ │ └── product_csv │ │ └── 1.csv │ ├── site │ └── site.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ ├── .gitignore │ └── sample.sql ├── batch-entry ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── com.springsource.sts.config.flow.prefs │ └── org.eclipse.jdt.core.prefs ├── .springBeans ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ └── batch │ │ │ ├── exception │ │ │ └── BatchSkipException.java │ │ │ └── step │ │ │ ├── EntryItemProcessor.java │ │ │ ├── EntryItemReader.java │ │ │ └── EntryItemWriter.java │ └── resources │ │ ├── META-INF │ │ ├── jdbc.properties │ │ ├── schema-init-hsqldb.sql │ │ └── spring │ │ │ └── job-context.xml │ │ ├── batch-context.xml │ │ └── log4j.properties │ ├── site │ └── site.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── cache ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── config │ │ │ └── applicationContext.xml │ │ │ └── di │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Product.java │ │ │ └── service │ │ │ │ ├── ProductDao.java │ │ │ │ ├── ProductService.java │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ └── ProductDaoImpl.java │ └── resources │ │ ├── log4j.dtd │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── di-annotation ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── config │ │ │ └── applicationContext.xml │ │ │ └── di │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Product.java │ │ │ └── service │ │ │ │ ├── ProductDao.java │ │ │ │ ├── ProductService.java │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ └── ProductDaoImpl.java │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── di-config ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── config │ │ │ └── applicationContext.xml │ │ │ └── di │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Product.java │ │ │ └── service │ │ │ │ ├── ProductDao.java │ │ │ │ ├── ProductService.java │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ └── ProductDaoImpl.java │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── di-javaconfig ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ProductSampleRun.java │ │ │ ├── config │ │ │ └── AppConfig.java │ │ │ └── di │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Product.java │ │ │ └── service │ │ │ │ ├── ProductDao.java │ │ │ │ ├── ProductService.java │ │ │ │ └── ProductServiceImpl.java │ │ │ └── dataaccess │ │ │ └── ProductDaoImpl.java │ └── resources │ │ └── log4j.xml │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── hibernate ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── Main.java │ │ │ ├── config │ │ │ ├── DataSourceConfig.java │ │ │ ├── HibernateConfig.java │ │ │ └── spring-hibernate.xml │ │ │ └── hibernate │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Pet.java │ │ │ └── service │ │ │ │ └── PetDao.java │ │ │ └── dataaccess │ │ │ ├── HibernatePetDao.java │ │ │ └── Pet.hbm.xml │ └── resources │ │ ├── db.properties │ │ ├── log4j.properties │ │ └── script │ │ ├── data.sql │ │ └── table.sql │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── jpa ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── JndiMain.java │ │ │ ├── Main.java │ │ │ ├── config │ │ │ ├── DataSourceConfig.java │ │ │ ├── JpaConfig.java │ │ │ ├── JpaJndiConfig.java │ │ │ ├── spring-jpa-jndi.xml │ │ │ └── spring-jpa.xml │ │ │ └── jpa │ │ │ ├── business │ │ │ ├── domain │ │ │ │ ├── Owner.java │ │ │ │ └── Pet.java │ │ │ └── service │ │ │ │ └── PetDao.java │ │ │ └── dataaccess │ │ │ └── JpaPetDao.java │ └── resources │ │ ├── db.properties │ │ ├── log4j.properties │ │ └── script │ │ ├── data.sql │ │ └── table.sql │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── mvc ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── .springBeans ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ └── customer │ │ │ ├── biz │ │ │ ├── domain │ │ │ │ └── Customer.java │ │ │ └── service │ │ │ │ ├── CustomerService.java │ │ │ │ ├── DataNotFoundException.java │ │ │ │ └── MockCustomerService.java │ │ │ ├── config │ │ │ ├── BizConfig.java │ │ │ └── WebConfig.java │ │ │ └── web │ │ │ └── controller │ │ │ ├── CustomerControllerAdvice.java │ │ │ ├── CustomerEditController.java │ │ │ ├── CustomerListController.java │ │ │ └── CustomerRestController.java │ ├── resources │ │ ├── META-INF │ │ │ ├── messages.properties │ │ │ └── spring │ │ │ │ ├── beans-biz.xml │ │ │ │ └── beans-webmvc.xml │ │ ├── log4j.dtd │ │ └── log4j.xml │ └── webapp │ │ └── WEB-INF │ │ ├── views │ │ ├── customer │ │ │ ├── detail.jsp │ │ │ ├── edit │ │ │ │ ├── edited.jsp │ │ │ │ ├── enter.jsp │ │ │ │ └── review.jsp │ │ │ ├── list.jsp │ │ │ └── notfound.jsp │ │ └── error.jsp │ │ └── web.xml │ └── test │ └── java │ └── sample │ └── customer │ └── biz │ └── domain │ ├── FindCustomerByIdMain.java │ └── RegisterCustomerMain.java ├── mybatis ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── Main.java │ │ │ ├── MainForMapper.java │ │ │ ├── config │ │ │ ├── DataSourceConfig.java │ │ │ ├── MyBatisConfig.java │ │ │ ├── MyBatisConfigForMapper.java │ │ │ ├── mybatis-config.xml │ │ │ ├── spring-mybatis-mapper.xml │ │ │ └── spring-mybatis.xml │ │ │ └── mybatis │ │ │ ├── business │ │ │ ├── domain │ │ │ │ └── Pet.java │ │ │ └── service │ │ │ │ └── PetDao.java │ │ │ └── dataaccess │ │ │ ├── MyBatisPetDao.java │ │ │ └── pet.xml │ └── resources │ │ ├── db.properties │ │ ├── log4j.properties │ │ └── script │ │ ├── data.sql │ │ └── table.sql │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── security ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── .springBeans ├── pom.xml └── src │ └── main │ ├── java │ └── sample │ │ └── security │ │ ├── authentication │ │ ├── SampleJdbcDaoImpl.java │ │ └── SampleUser.java │ │ └── config │ │ ├── DataAccessMockConfig.java │ │ ├── SecurityConfigInMemory.java │ │ └── SecurityConfigJdbc.java │ ├── resources │ ├── META-INF │ │ ├── db │ │ │ ├── ddl.sql │ │ │ └── dml.sql │ │ └── spring │ │ │ ├── beans-dataaccess-mock.xml │ │ │ ├── beans-security-in-memory.xml │ │ │ └── beans-security-jdbc.xml │ ├── log4j.dtd │ └── log4j.xml │ └── webapp │ ├── WEB-INF │ └── web.xml │ ├── accessDenied.jsp │ ├── admin │ └── admin.jsp │ ├── login.jsp │ ├── top.jsp │ └── user │ └── user.jsp ├── springdatajpa ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── Main.java │ │ │ ├── config │ │ │ ├── AppConfig.java │ │ │ ├── DataSourceConfig.java │ │ │ ├── JpaConfig.java │ │ │ └── spring-jpa.xml │ │ │ └── springdatajpa │ │ │ ├── business │ │ │ ├── domain │ │ │ │ ├── Owner.java │ │ │ │ └── Pet.java │ │ │ └── service │ │ │ │ ├── PetDao.java │ │ │ │ └── PetDaoCustom.java │ │ │ └── dataaccess │ │ │ └── PetDaoImpl.java │ └── resources │ │ ├── db.properties │ │ ├── log4j.properties │ │ └── script │ │ ├── data.sql │ │ └── table.sql │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore ├── springjdbc ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ ├── ExecuteSqlMain.java │ │ │ ├── JndiMain.java │ │ │ ├── config │ │ │ ├── DataSourceConfig.java │ │ │ ├── JndiConfig.java │ │ │ ├── TemplateConfig.java │ │ │ ├── spring-db.xml │ │ │ └── spring-jndi.xml │ │ │ └── springjdbc │ │ │ └── business │ │ │ └── domain │ │ │ ├── Owner.java │ │ │ └── Pet.java │ └── resources │ │ ├── jdbc.properties │ │ ├── jndi.properties │ │ ├── log4j.properties │ │ └── script │ │ ├── data.sql │ │ ├── proc.sql │ │ └── table.sql │ └── test │ ├── java │ └── .gitignore │ └── resources │ └── .gitignore └── transaction ├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── ReadMe.txt ├── pom.xml └── src ├── main ├── java │ └── sample │ │ ├── TranByAnnotationMain.java │ │ ├── TranByFileMain.java │ │ ├── TranByJavaConfigMain.java │ │ ├── TranByProgrammaticMain.java │ │ ├── biz │ │ ├── dao │ │ │ └── PetDao.java │ │ ├── domain │ │ │ ├── Owner.java │ │ │ └── Pet.java │ │ ├── exception │ │ │ └── BussinessException.java │ │ └── service │ │ │ ├── PetService.java │ │ │ └── impl │ │ │ └── PetServiceImpl.java │ │ ├── config │ │ ├── TransactionConfig.java │ │ ├── spring-tranByAnnotation.xml │ │ ├── spring-tranByFile.xml │ │ └── spring-tranByProgrammatic.xml │ │ └── dao │ │ └── PetDaoSpringJdbc.java └── resources │ ├── log4j.properties │ └── script │ ├── data.sql │ └── table.sql └── test ├── java └── .gitignore └── resources └── .gitignore /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /aop-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /aop-annotation/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /aop-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | aop-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /aop-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /aop-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /aop-annotation/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의 「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import sample.aop.business.domain.Product; 7 | import sample.aop.business.service.ProductService; 8 | 9 | public class ProductSampleRun { 10 | 11 | public static void main(String[] args) { 12 | ProductSampleRun productSampleRun = new ProductSampleRun(); 13 | productSampleRun.execute(); 14 | } 15 | 16 | @SuppressWarnings("resource") 17 | public void execute() { 18 | // BeanFactory는 ApplicationContext에 적어도 괜찮습니다. 19 | BeanFactory ctx = new ClassPathXmlApplicationContext("/sample/config/applicationContext.xml"); 20 | ProductService productService = ctx.getBean(ProductService.class); 21 | 22 | productService.addProduct(new Product("공책", 100)); 23 | 24 | Product product = productService.findByProductName("공책"); 25 | System.out.println(product); 26 | } 27 | } -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/aop/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/aop/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | 8 | Product findProduct(String name); 9 | } 10 | -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/aop/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/aop/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import sample.aop.business.domain.Product; 7 | 8 | @Component 9 | public class ProductServiceImpl implements ProductService { 10 | @Autowired 11 | private ProductDao productDao; 12 | 13 | public void addProduct(Product product) { 14 | productDao.addProduct(product); 15 | } 16 | 17 | public Product findByProductName(String name) { 18 | return productDao.findProduct(name); 19 | } 20 | } -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/aop/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import sample.aop.business.domain.Product; 9 | import sample.aop.business.service.ProductDao; 10 | 11 | @Component 12 | public class ProductDaoImpl implements ProductDao { 13 | // Dao만으로 간단하게 구현하게 위해서 RDB에 접속은 하지 않습니다. 14 | // Map은 RDB대신으로 사용 15 | private Map storage = new HashMap(); 16 | 17 | public Product findProduct(String name) { 18 | return storage.get(name); 19 | } 20 | 21 | public void addProduct(Product product) { 22 | storage.put(product.getName(), product); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aop-annotation/src/main/java/sample/config/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /aop-annotation/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /aop-annotation/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-annotation/src/test/java/.gitignore -------------------------------------------------------------------------------- /aop-annotation/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-annotation/src/test/resources/.gitignore -------------------------------------------------------------------------------- /aop-config/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /aop-config/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /aop-config/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | aop-config 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /aop-config/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /aop-config/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /aop-config/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import sample.aop.business.domain.Product; 7 | import sample.aop.business.service.ProductService; 8 | 9 | public class ProductSampleRun { 10 | 11 | public static void main(String[] args) { 12 | ProductSampleRun productSampleRun = new ProductSampleRun(); 13 | productSampleRun.execute(); 14 | } 15 | 16 | @SuppressWarnings("resource") 17 | public void execute() { 18 | BeanFactory ctx = new ClassPathXmlApplicationContext("/sample/config/applicationContext.xml"); 19 | ProductService productService = ctx.getBean(ProductService.class); 20 | 21 | productService.addProduct(new Product("공책", 100)); 22 | 23 | Product product = productService.findByProductName("공책"); 24 | System.out.println(product); 25 | } 26 | } -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/aop/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/aop/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | 8 | Product findProduct(String name); 9 | } 10 | -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/aop/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/aop/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import sample.aop.business.domain.Product; 7 | 8 | @Component 9 | public class ProductServiceImpl implements ProductService { 10 | @Autowired 11 | private ProductDao productDao; 12 | 13 | public void addProduct(Product product) { 14 | productDao.addProduct(product); 15 | } 16 | 17 | public Product findByProductName(String name) { 18 | return productDao.findProduct(name); 19 | } 20 | } -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/aop/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import sample.aop.business.domain.Product; 9 | import sample.aop.business.service.ProductDao; 10 | 11 | @Component 12 | public class ProductDaoImpl implements ProductDao { 13 | // Dao만으로 간단하게 구현하게 위해서 RDB에 접속은 하지 않습니다. 14 | // Map은 RDB대신으로 사용 15 | private Map storage = new HashMap(); 16 | 17 | public Product findProduct(String name) { 18 | return storage.get(name); 19 | } 20 | 21 | public void addProduct(Product product) { 22 | storage.put(product.getName(), product); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aop-config/src/main/java/sample/config/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /aop-config/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /aop-config/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-config/src/test/java/.gitignore -------------------------------------------------------------------------------- /aop-config/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-config/src/test/resources/.gitignore -------------------------------------------------------------------------------- /aop-javaconfig/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /aop-javaconfig/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /aop-javaconfig/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | aop-javaconfig 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /aop-javaconfig/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /aop-javaconfig/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /aop-javaconfig/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | import sample.aop.business.domain.Product; 7 | import sample.aop.business.service.ProductService; 8 | import sample.config.AppConfig; 9 | 10 | public class ProductSampleRun { 11 | 12 | public static void main(String[] args) { 13 | ProductSampleRun productSampleRun = new ProductSampleRun(); 14 | productSampleRun.execute(); 15 | } 16 | 17 | @SuppressWarnings("resource") 18 | public void execute() { 19 | BeanFactory ctx = new AnnotationConfigApplicationContext(AppConfig.class); 20 | 21 | ProductService productService = ctx.getBean(ProductService.class); 22 | 23 | productService.addProduct(new Product("공책", 100)); 24 | 25 | Product product = productService.findByProductName("공책"); 26 | System.out.println(product); 27 | } 28 | } -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/aop/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/aop/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | 8 | Product findProduct(String name); 9 | } 10 | -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/aop/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import sample.aop.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/aop/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import sample.aop.business.domain.Product; 6 | 7 | public class ProductServiceImpl implements ProductService { 8 | @Autowired 9 | private ProductDao productDao; 10 | 11 | public void addProduct(Product product) { 12 | productDao.addProduct(product); 13 | } 14 | 15 | public Product findByProductName(String name) { 16 | return productDao.findProduct(name); 17 | } 18 | } -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/aop/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.aop.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import sample.aop.business.domain.Product; 7 | import sample.aop.business.service.ProductDao; 8 | 9 | public class ProductDaoImpl implements ProductDao { 10 | // Dao만으로 간단하게 구현하게 위해서 RDB에 접속은 하지 않습니다. 11 | // Map은 RDB대신으로 사용 12 | private Map storage = new HashMap(); 13 | 14 | public Product findProduct(String name) { 15 | return storage.get(name); 16 | } 17 | 18 | public void addProduct(Product product) { 19 | storage.put(product.getName(), product); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /aop-javaconfig/src/main/java/sample/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | import sample.aop.MyFirstAspect; 8 | import sample.aop.business.service.ProductServiceImpl; 9 | import sample.aop.dataaccess.ProductDaoImpl; 10 | 11 | @Configuration 12 | @EnableAspectJAutoProxy 13 | public class AppConfig { 14 | @Bean 15 | public ProductServiceImpl productService() { 16 | return new ProductServiceImpl(); 17 | } 18 | 19 | @Bean 20 | public ProductDaoImpl productDao() { 21 | return new ProductDaoImpl(); 22 | } 23 | 24 | @Bean 25 | public MyFirstAspect myFirstAspect() { 26 | return new MyFirstAspect(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aop-javaconfig/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /aop-javaconfig/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-javaconfig/src/test/java/.gitignore -------------------------------------------------------------------------------- /aop-javaconfig/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/aop-javaconfig/src/test/resources/.gitignore -------------------------------------------------------------------------------- /batch-advanced/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /batch-advanced/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /batch-advanced/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | batch-advanced 4 | This plugin is an archetype that creates a command line batch sample from Spring Batch. Once installed you can create the archetype project using<br/><pre>$ mvn archetype:create -DgroupId=com.first -DartifactId=batch \ -DarchetypeGroupId=org.springframework.batch \ -DarchetypeArtifactId=spring-batch-cli -DarchetypeVersion=1.0-m3-SNAPSHOT</pre><br/> Then you should be able to "cd batch; mvn package exec:exec", and see the app run. 5 | 6 | 7 | 8 | 9 | 10 | org.eclipse.jdt.core.javabuilder 11 | 12 | 13 | 14 | 15 | org.springframework.ide.eclipse.core.springbuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Builder 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.ide.eclipse.core.springnature 27 | org.eclipse.jdt.core.javanature 28 | org.eclipse.m2e.core.maven2Nature 29 | 30 | 31 | -------------------------------------------------------------------------------- /batch-advanced/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /batch-advanced/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/batch-context.xml 11 | src/main/resources/META-INF/spring/job-context.xml 12 | src/main/resources/META-INF/spring/item-context.xml 13 | 14 | 15 | 16 | 17 | 18 | 19 | true 20 | false 21 | 22 | src/main/resources/batch-context.xml 23 | src/main/resources/META-INF/spring/job-context.xml 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /batch-advanced/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제의 실행 방법*** 2 | [HSQLDB의 실행] 3 | 1.HSQLDB 실행하기. 4 | 1-1. HSQLDB(1.8.0)를 다운로드 한다. 5 | 1−2. %HSQLDB_HOME%¥lib폴더에 이동. 이하의 커맨드로 HSQLDB를 서버 모드로 실행한다. 6 | ・java -cp hsqldb.jar org.hsqldb.Server -database db/test 7 | 1−2. 동일하게 lib폴더에서 이하의 커맨드로 DatabaseManager를 실행한다. 8 | ・java -cp hsqldb.jar org.hsqldb.util.DatabaseManager 9 | ・다이어로그가 표시되면 Type에서 "HSQL Database Engine Server"를 선택 10 | 11 | [Eclipse에서의 실행 방법] 12 | 1.batch-advanced프로젝트를 선택한 다음, 우 클릭으로 [Run as > Run Configurations...]를 선택 13 | 2.다이어로그가 표시되면 main탭의 프로젝트에 [batch-advanced]를, main클래스에는 [org.springframework.batch.core.launch.support.CommandLineJobRunner]를 설정 14 | 3.Argument탭을 선택해 Program arguments에 [classpath:/batch-context.xml job1 inputFile=classpath:/product_csv/1.csv]를 설정 15 | 4.Run버튼을 클릭하면 배치가 실행됩니다. 16 | 5.DatabaseManager에서 배치를 실행하여 테이블(필요하다면 DatabaseManager에서 View>Reflesh Tree를 실행) 및 CVS파일이 변경된 것을 확인한다. 17 | 18 | [주의] 19 | item-context.xml에서 member.csv의 출력 위치가 [c:/member.csv]로 되어 있으므로 필요하다면 출력 위치를 변경합니다. -------------------------------------------------------------------------------- /batch-advanced/src/main/java/sample/business/domain/Member.java: -------------------------------------------------------------------------------- 1 | package sample.business.domain; 2 | 3 | public class Member { 4 | private int memberId; 5 | private String name; 6 | 7 | public int getMemberId() { 8 | return memberId; 9 | } 10 | 11 | public void setMemberId(int memberId) { 12 | this.memberId = memberId; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /batch-advanced/src/main/java/sample/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.business.domain; 2 | 3 | import javax.validation.constraints.NotNull; 4 | import javax.validation.constraints.Size; 5 | 6 | import org.hibernate.validator.constraints.Range; 7 | 8 | 9 | public class Product { 10 | @NotNull 11 | @Size(max=10) 12 | private String name; 13 | 14 | @NotNull 15 | @Range(min=50, max=900) 16 | private int price; 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public void setPrice(int price) { 23 | this.price = price; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public int getPrice() { 31 | return price; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Product [name=" + name + ", price=" + price + "]"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /batch-advanced/src/main/resources/META-INF/jdbc.properties: -------------------------------------------------------------------------------- 1 | # HSQLDB 2 | batch.jdbc.driver=org.hsqldb.jdbcDriver 3 | batch.jdbc.url=jdbc:hsqldb:hsql://localhost/ 4 | batch.jdbc.user=sa 5 | batch.jdbc.password= 6 | batch.schema= 7 | batch.schema.init.script=classpath:/META-INF/schema-init-hsqldb.sql 8 | #batch.schema.init.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql 9 | #batch.schema.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql 10 | -------------------------------------------------------------------------------- /batch-advanced/src/main/resources/META-INF/spring/job-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /batch-advanced/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=ERROR, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n 6 | 7 | log4j.logger.org.apache.activemq=ERROR 8 | # log4j.logger.org.springframework.batch=DEBUG 9 | # log4j.logger.org.springframework.transaction=INFO 10 | 11 | log4j.logger.test.jdbc=DEBUG 12 | # for debugging datasource initialization 13 | # log4j.category.test.jdbc=DEBUG 14 | -------------------------------------------------------------------------------- /batch-advanced/src/main/resources/product_csv/1.csv: -------------------------------------------------------------------------------- 1 | name,price 2 | Pen,100 3 | Apple,200 -------------------------------------------------------------------------------- /batch-advanced/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Batch: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /batch-advanced/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-advanced/src/test/java/.gitignore -------------------------------------------------------------------------------- /batch-advanced/src/test/java/sample.sql: -------------------------------------------------------------------------------- 1 | create table product( 2 | name varchar(20), 3 | price int); 4 | 5 | create table member ( 6 | member_id int, 7 | name varchar(20)); 8 | 9 | insert into member values(100, 'ChulSoo Kim'); 10 | insert into member values(112, 'Tiger Woods'); -------------------------------------------------------------------------------- /batch-advanced/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-advanced/src/test/resources/.gitignore -------------------------------------------------------------------------------- /batch-advanced/src/test/resources/sample.sql: -------------------------------------------------------------------------------- 1 | create table product( 2 | name varchar(20), 3 | price int); 4 | 5 | create table member( 6 | member_id int, 7 | name varchar(20)); 8 | 9 | create table facility( 10 | name varchar(20), 11 | address varchar(20)); -------------------------------------------------------------------------------- /batch-basic/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /batch-basic/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /batch-basic/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | batch-basic 4 | This plugin is an archetype that creates a command line batch sample from Spring Batch. Once installed you can create the archetype project using<br/><pre>$ mvn archetype:create -DgroupId=com.first -DartifactId=batch \ -DarchetypeGroupId=org.springframework.batch \ -DarchetypeArtifactId=spring-batch-cli -DarchetypeVersion=1.0-m3-SNAPSHOT</pre><br/> Then you should be able to "cd batch; mvn package exec:exec", and see the app run. 5 | 6 | 7 | 8 | 9 | 10 | org.eclipse.jdt.core.javabuilder 11 | 12 | 13 | 14 | 15 | org.springframework.ide.eclipse.core.springbuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Builder 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.ide.eclipse.core.springnature 27 | org.eclipse.jdt.core.javanature 28 | org.eclipse.m2e.core.maven2Nature 29 | 30 | 31 | -------------------------------------------------------------------------------- /batch-basic/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /batch-basic/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/batch-context.xml 11 | src/main/resources/META-INF/spring/job-context.xml 12 | 13 | 14 | 15 | 16 | 17 | 18 | true 19 | false 20 | 21 | src/main/resources/batch-context.xml 22 | src/main/resources/META-INF/spring/job-context.xml 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /batch-basic/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제의 실행 방법*** 2 | [HSQLDB의 실행] 3 | 1.HSQLDB 실행하기. 4 | 1-1. HSQLDB(1.8.0)를 다운로드 한다. 5 | 1−2. %HSQLDB_HOME%¥lib폴더에 이동. 이하의 커맨드로 HSQLDB를 서버 모드로 실행한다. 6 | ・java -cp hsqldb.jar org.hsqldb.Server -database db/test 7 | 1−2. 동일하게 lib폴더에서 이하의 커맨드로 DatabaseManager를 실행한다. 8 | ・java -cp hsqldb.jar org.hsqldb.util.DatabaseManager 9 | ・다이어로그가 표시되면 Type에서 "HSQL Database Engine Server"를 선택 10 | 11 | [Eclipse에서의 실행 방법] 12 | 1.batch-advanced프로젝트를 선택한 다음, 우클릭으로 [Run as > Run Configurations...]를 선택 13 | 2.다이어로그가 표시되면 main탭의 프로젝트에 [batch-basic]를, main클래스에는 [org.springframework.batch.core.launch.support.CommandLineJobRunner]를 설정 14 | 3.Argument탭을 선택해 Program arguments에 [classpath:/batch-context.xml job1 inputFile=classpath:/product_csv/1.csv]를 설정 15 | 4.Run버튼을 클릭하면 배치가 실행됩니다. 16 | 5.DatabaseManager에서 배치를 실행하여 테이블이 변경된 것을 확인한다.(필요하다면 DatabaseManager에서 View>Reflesh Tree를 실행) 17 | -------------------------------------------------------------------------------- /batch-basic/src/main/java/sample/batch/listener/SampleChunkListener.java: -------------------------------------------------------------------------------- 1 | package sample.batch.listener; 2 | 3 | import org.springframework.batch.core.annotation.AfterChunk; 4 | import org.springframework.batch.core.annotation.BeforeChunk; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class SampleChunkListener { 9 | 10 | @BeforeChunk 11 | public void beforeChunk() { 12 | System.out.println("*** before Chunk"); 13 | } 14 | 15 | @AfterChunk 16 | public void afterChunk() { 17 | System.out.println("*** after Chunk"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /batch-basic/src/main/java/sample/batch/listener/SampleStepExecutionListener.java: -------------------------------------------------------------------------------- 1 | package sample.batch.listener; 2 | 3 | import org.springframework.batch.core.ExitStatus; 4 | import org.springframework.batch.core.StepExecution; 5 | import org.springframework.batch.core.annotation.AfterStep; 6 | import org.springframework.batch.core.annotation.BeforeStep; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component("sampleStepExecutionListener") 10 | public class SampleStepExecutionListener { 11 | 12 | @BeforeStep 13 | public void beforeStep(StepExecution stepExecution) { 14 | System.out.println("*** Before Step :Start Time " + stepExecution.getStartTime()); 15 | } 16 | 17 | @AfterStep 18 | public ExitStatus afterStep(StepExecution stepExecution) { 19 | System.out.println("*** After Step :Commit Count " + stepExecution.getCommitCount()); 20 | return ExitStatus.COMPLETED; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /batch-basic/src/main/java/sample/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.business.domain; 2 | 3 | import javax.validation.constraints.NotNull; 4 | import javax.validation.constraints.Size; 5 | 6 | import org.hibernate.validator.constraints.Range; 7 | 8 | 9 | public class Product { 10 | @NotNull 11 | @Size(max=10) 12 | private String name; 13 | 14 | @NotNull 15 | @Range(min=50, max=900) 16 | private int price; 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public void setPrice(int price) { 23 | this.price = price; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public int getPrice() { 31 | return price; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Product [name=" + name + ", price=" + price + "]"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /batch-basic/src/main/resources/META-INF/jdbc.properties: -------------------------------------------------------------------------------- 1 | # HSQLDB 2 | batch.jdbc.driver=org.hsqldb.jdbcDriver 3 | batch.jdbc.url=jdbc:hsqldb:hsql://localhost/ 4 | batch.jdbc.user=sa 5 | batch.jdbc.password= 6 | batch.schema= 7 | batch.schema.init.script=classpath:/META-INF/schema-init-hsqldb.sql 8 | #batch.schema.init.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql 9 | #batch.schema.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql 10 | -------------------------------------------------------------------------------- /batch-basic/src/main/resources/META-INF/spring/job-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /batch-basic/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=ERROR, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n 6 | 7 | log4j.logger.org.apache.activemq=ERROR 8 | # log4j.logger.org.springframework.batch=DEBUG 9 | # log4j.logger.org.springframework.transaction=INFO 10 | 11 | log4j.logger.test.jdbc=DEBUG 12 | # for debugging datasource initialization 13 | # log4j.category.test.jdbc=DEBUG 14 | -------------------------------------------------------------------------------- /batch-basic/src/main/resources/product_csv/1.csv: -------------------------------------------------------------------------------- 1 | name,price 2 | Pen,100 3 | Apple,200 4 | -------------------------------------------------------------------------------- /batch-basic/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Batch: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /batch-basic/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-basic/src/test/java/.gitignore -------------------------------------------------------------------------------- /batch-basic/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-basic/src/test/resources/.gitignore -------------------------------------------------------------------------------- /batch-basic/src/test/resources/sample.sql: -------------------------------------------------------------------------------- 1 | create table product( 2 | name varchar(20), 3 | price int); -------------------------------------------------------------------------------- /batch-entry/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /batch-entry/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /batch-entry/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | batch-entry 4 | This plugin is an archetype that creates a command line batch sample from Spring Batch. Once installed you can create the archetype project using<br/><pre>$ mvn archetype:create -DgroupId=com.first -DartifactId=batch \ -DarchetypeGroupId=org.springframework.batch \ -DarchetypeArtifactId=spring-batch-cli -DarchetypeVersion=1.0-m3-SNAPSHOT</pre><br/> Then you should be able to "cd batch; mvn package exec:exec", and see the app run. 5 | 6 | 7 | 8 | 9 | 10 | org.eclipse.jdt.core.javabuilder 11 | 12 | 13 | 14 | 15 | org.springframework.ide.eclipse.core.springbuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Builder 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.ide.eclipse.core.springnature 27 | org.eclipse.jdt.core.javanature 28 | org.eclipse.m2e.core.maven2Nature 29 | 30 | 31 | -------------------------------------------------------------------------------- /batch-entry/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /batch-entry/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/batch-context.xml 11 | src/main/resources/META-INF/spring/job-context.xml 12 | 13 | 14 | 15 | 16 | 17 | 18 | true 19 | false 20 | 21 | src/main/resources/batch-context.xml 22 | src/main/resources/META-INF/spring/job-context.xml 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /batch-entry/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제의 실행 방법*** 2 | [HSQLDB의 실행] 3 | 1.HSQLDB가 실행되어 있지 않다면 HSQLDB를 인메모리 모드로 실행한다. 4 | 1-1. HSQLDB(1.8.0)를 다운로드하여 lib폴더에서 이하의 커맨드를 사용하여 실행한다.(이 예제에서는 인 메모리) 5 | ・java -cp hsqldb.jar org.hsqldb.util.DatabaseManager 6 | 7 | [Eclipse에서의 실행 방법] 8 | 1.batch-entry프로젝트를 선택한 다음, 우클릭으로 [Run as > Run Configurations...]를 선택 9 | 2.다이어로그가 표시되면 main탭의 프로젝트에 [batch-entry]를, main클래스에는 [org.springframework.batch.core.launch.support.CommandLineJobRunner]를 설정 10 | 3.Argument탭을 선택해 Program arguments에 [classpath:/batch-context.xml job1]를 설정 11 | 4.Run버튼을 클릭하면 배치가 실행됩니다.(콘솔 뷰에서 실행을 확인 가능) 12 | 13 | [에러 처리의 확인] 14 | EntryItemReader클래스의 input을 다음과 같이 변경해서 에러를 확인할 수 있음 15 | private String[] input = {"Hello World", "hoge", "hoge", null}; -------------------------------------------------------------------------------- /batch-entry/src/main/java/sample/batch/exception/BatchSkipException.java: -------------------------------------------------------------------------------- 1 | package sample.batch.exception; 2 | 3 | public class BatchSkipException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public BatchSkipException() { 7 | } 8 | 9 | public BatchSkipException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public BatchSkipException(Throwable th) { 14 | super(th); 15 | } 16 | 17 | public BatchSkipException(String msg, Throwable th) { 18 | super(msg, th); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /batch-entry/src/main/java/sample/batch/step/EntryItemProcessor.java: -------------------------------------------------------------------------------- 1 | package sample.batch.step; 2 | 3 | import org.springframework.batch.item.ItemProcessor; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component("itemProcessor") 7 | public class EntryItemProcessor implements 8 | ItemProcessor { 9 | 10 | public String process(String message) 11 | throws Exception { 12 | return message + "!!"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /batch-entry/src/main/java/sample/batch/step/EntryItemReader.java: -------------------------------------------------------------------------------- 1 | package sample.batch.step; 2 | 3 | import org.springframework.batch.item.ItemReader; 4 | import org.springframework.stereotype.Component; 5 | 6 | import sample.batch.exception.BatchSkipException; 7 | 8 | @Component("itemReader") 9 | public class EntryItemReader implements ItemReader { 10 | 11 | private String[] input = {"Hello World", "hoge", "안녕하세요", null}; 12 | 13 | private int index = 0; 14 | 15 | /** 16 | * Reads next record from input 17 | */ 18 | public String read() throws Exception { 19 | 20 | String message = input[index++]; 21 | 22 | if(message == null) { 23 | return null; 24 | } 25 | if (message.equals("hoge")) { 26 | throw new BatchSkipException("데이터 에러" 27 | + message + "]"); 28 | } 29 | return message; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /batch-entry/src/main/java/sample/batch/step/EntryItemWriter.java: -------------------------------------------------------------------------------- 1 | package sample.batch.step; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.batch.item.ItemWriter; 6 | import org.springframework.stereotype.Component; 7 | 8 | 9 | @Component("itemWriter") 10 | public class EntryItemWriter implements ItemWriter { 11 | 12 | public void write(List data) throws Exception { 13 | System.out.println(data); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /batch-entry/src/main/resources/META-INF/jdbc.properties: -------------------------------------------------------------------------------- 1 | # HSQLDB 2 | batch.jdbc.driver=org.hsqldb.jdbcDriver 3 | batch.jdbc.url=jdbc:hsqldb:mem:. 4 | batch.jdbc.user=sa 5 | batch.jdbc.password= 6 | batch.schema= 7 | batch.schema.init.script=classpath:/META-INF/schema-init-hsqldb.sql 8 | #batch.schema.init.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql 9 | #batch.schema.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql 10 | -------------------------------------------------------------------------------- /batch-entry/src/main/resources/META-INF/spring/job-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /batch-entry/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=ERROR, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n 6 | 7 | log4j.logger.org.apache.activemq=ERROR 8 | # log4j.logger.org.springframework.batch=DEBUG 9 | # log4j.logger.org.springframework.transaction=INFO 10 | 11 | log4j.logger.test.jdbc=DEBUG 12 | # for debugging datasource initialization 13 | # log4j.category.test.jdbc=DEBUG 14 | -------------------------------------------------------------------------------- /batch-entry/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Batch: ${project.name} 6 | index.html 7 | 8 | 9 | 10 | org.springframework.maven.skins 11 | maven-spring-skin 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /batch-entry/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-entry/src/test/java/.gitignore -------------------------------------------------------------------------------- /batch-entry/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/batch-entry/src/test/resources/.gitignore -------------------------------------------------------------------------------- /cache/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /cache/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /cache/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cache 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /cache/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /cache/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /cache/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제의 실행 방법*** 2 | 1."src/main/java" 폴더의 "sample" 패키지 내에 있는 "ProductSampleRun.java"를 선택 3 | 2.우클릭으로 "Run As > Java Application"를 선택하여 실행 4 | 3.결과는 Console뷰에서 확인 -------------------------------------------------------------------------------- /cache/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import sample.di.business.domain.Product; 7 | import sample.di.business.service.ProductService; 8 | 9 | public class ProductSampleRun { 10 | 11 | public static void main(String[] args) { 12 | ProductSampleRun productSampleRun = new ProductSampleRun(); 13 | productSampleRun.execute(); 14 | } 15 | 16 | public void execute() { 17 | ProductService productService = initProductService(); 18 | 19 | String productName = "hoge"; 20 | productService.addProduct(new Product(productName, 100)); 21 | productService.findProduct(productName); 22 | productService.findProduct(productName); 23 | productService.findProduct(productName); 24 | 25 | productService.addProduct(new Product(productName, 200)); 26 | productService.findProduct(productName); 27 | productService.findProduct(productName); 28 | productService.findProduct(productName); 29 | } 30 | 31 | private ProductService initProductService() { 32 | @SuppressWarnings("resource") 33 | ApplicationContext ctx = new ClassPathXmlApplicationContext( 34 | "/sample/config/applicationContext.xml"); 35 | ProductService productService = ctx.getBean(ProductService.class); 36 | return productService; 37 | } 38 | } -------------------------------------------------------------------------------- /cache/src/main/java/sample/config/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /cache/src/main/java/sample/di/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Product implements Serializable { 6 | private String name; 7 | private int price; 8 | 9 | public Product(String name, int price) { 10 | this.name = name; 11 | this.price = price; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public int getPrice() { 19 | return price; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Product= [name=" + name + ", price=" + price + "]"; 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | final int prime = 31; 30 | int result = 1; 31 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 32 | result = prime * result + price; 33 | return result; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (this == obj) 39 | return true; 40 | if (obj == null) 41 | return false; 42 | if (getClass() != obj.getClass()) 43 | return false; 44 | Product other = (Product) obj; 45 | if (name == null) { 46 | if (other.name != null) 47 | return false; 48 | } else if (!name.equals(other.name)) 49 | return false; 50 | if (price != other.price) 51 | return false; 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cache/src/main/java/sample/di/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | Product findProduct(String name); 7 | void addProduct(Product product); 8 | } 9 | -------------------------------------------------------------------------------- /cache/src/main/java/sample/di/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductService { 6 | Product findProduct(String name); 7 | void addProduct(Product product); 8 | } 9 | -------------------------------------------------------------------------------- /cache/src/main/java/sample/di/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.util.StopWatch; 6 | 7 | import sample.di.business.domain.Product; 8 | 9 | @Service 10 | public class ProductServiceImpl implements ProductService { 11 | @Autowired 12 | private ProductDao productDao; 13 | 14 | public Product findProduct(String name) { 15 | 16 | // 측정 시작 17 | StopWatch sw = new StopWatch(); 18 | sw.start(); 19 | 20 | Product product = productDao.findProduct(name); 21 | 22 | // 측정 종료 23 | sw.stop(); 24 | 25 | System.out.format("Seconds=%1$s, value=%2$s%n", 26 | sw.getTotalTimeSeconds(), product); 27 | 28 | return product; 29 | } 30 | 31 | public void addProduct(Product product) { 32 | productDao.addProduct(product); 33 | } 34 | } -------------------------------------------------------------------------------- /cache/src/main/java/sample/di/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.cache.annotation.CacheEvict; 7 | import org.springframework.cache.annotation.Cacheable; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import sample.di.business.domain.Product; 11 | import sample.di.business.service.ProductDao; 12 | 13 | @Repository 14 | public class ProductDaoImpl implements ProductDao { 15 | 16 | // RDB의 대체 17 | private Map storage = new HashMap(); 18 | 19 | // Dao이지만 단순화 하기 위해 RDB에는 액세스 하지 않음 20 | @Cacheable(value = "area") 21 | public Product findProduct(String name) { 22 | slowly(); // 고의로 지연시킴 23 | return storage.get(name); 24 | } 25 | 26 | //@CacheEvict(value = "product", allEntries = true) 모든 캐시 엔트리 삭제 27 | @CacheEvict(value = "area", key = "#product.name") 28 | public void addProduct(Product product) { 29 | storage.put(product.getName(), product); 30 | } 31 | 32 | private void slowly() { 33 | try { 34 | Thread.sleep(3000L); 35 | } catch (InterruptedException e) { 36 | throw new IllegalStateException(e); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /cache/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cache/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/cache/src/test/java/.gitignore -------------------------------------------------------------------------------- /cache/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/cache/src/test/resources/.gitignore -------------------------------------------------------------------------------- /di-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /di-annotation/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /di-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | di-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /di-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /di-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /di-annotation/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.beans.factory.BeanFactory; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import sample.di.business.domain.Product; 7 | import sample.di.business.service.ProductService; 8 | 9 | public class ProductSampleRun { 10 | 11 | public static void main(String[] args) { 12 | ProductSampleRun productSampleRun = new ProductSampleRun(); 13 | productSampleRun.execute(); 14 | } 15 | 16 | @SuppressWarnings("resource") 17 | public void execute() { 18 | // BeanFactory는ApplicationContext에서 변경해도 괜찮습니다 19 | BeanFactory ctx = new ClassPathXmlApplicationContext( 20 | "/sample/config/applicationContext.xml"); 21 | ProductService productService = ctx.getBean(ProductService.class); 22 | 23 | productService.addProduct(new Product("공책", 100)); 24 | 25 | Product product = productService.findByProductName("공책"); 26 | System.out.println(product); 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/config/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/di/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/di/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/di/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/di/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import sample.di.business.domain.Product; 7 | 8 | @Component 9 | public class ProductServiceImpl implements ProductService { 10 | @Autowired 11 | private ProductDao productDao; 12 | 13 | public void addProduct(Product product) { 14 | productDao.addProduct(product); 15 | 16 | } 17 | 18 | public Product findByProductName(String name) { 19 | return productDao.findByProductName(name); 20 | } 21 | } -------------------------------------------------------------------------------- /di-annotation/src/main/java/sample/di/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import sample.di.business.domain.Product; 9 | import sample.di.business.service.ProductDao; 10 | 11 | @Component 12 | public class ProductDaoImpl implements ProductDao { 13 | // Dao만으로 간단하게 구현하게 위해서 RDB에 접속은 하지 않습니다. 14 | // Map은 RDB대신으로 사용 15 | private Map storage = new HashMap(); 16 | 17 | public Product findByProductName(String name) { 18 | return storage.get(name); 19 | } 20 | 21 | public void addProduct(Product product) { 22 | storage.put(product.getName(), product); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /di-annotation/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /di-annotation/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-annotation/src/test/java/.gitignore -------------------------------------------------------------------------------- /di-annotation/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-annotation/src/test/resources/.gitignore -------------------------------------------------------------------------------- /di-config/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /di-config/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /di-config/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | di-config 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /di-config/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /di-config/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /di-config/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /di-config/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import sample.di.business.domain.Product; 7 | import sample.di.business.service.ProductService; 8 | 9 | public class ProductSampleRun { 10 | 11 | public static void main(String[] args) { 12 | ProductSampleRun productSampleRun = new ProductSampleRun(); 13 | productSampleRun.execute(); 14 | } 15 | 16 | @SuppressWarnings("resource") 17 | public void execute() { 18 | ApplicationContext ctx = new ClassPathXmlApplicationContext( 19 | "/sample/config/applicationContext.xml"); 20 | ProductService productService = ctx.getBean(ProductService.class); 21 | 22 | productService.addProduct(new Product("공책", 100)); 23 | 24 | Product product = productService.findByProductName("공책"); 25 | System.out.println(product); 26 | } 27 | } -------------------------------------------------------------------------------- /di-config/src/main/java/sample/config/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /di-config/src/main/java/sample/di/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /di-config/src/main/java/sample/di/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-config/src/main/java/sample/di/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-config/src/main/java/sample/di/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public class ProductServiceImpl implements ProductService { 6 | private ProductDao productDao; 7 | 8 | public void setProductDao(ProductDao productDao) { 9 | this.productDao = productDao; 10 | } 11 | 12 | @Override 13 | public void addProduct(Product product) { 14 | productDao.addProduct(product); 15 | 16 | } 17 | 18 | @Override 19 | public Product findByProductName(String name) { 20 | return productDao.findByProductName(name); 21 | } 22 | } -------------------------------------------------------------------------------- /di-config/src/main/java/sample/di/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import sample.di.business.domain.Product; 7 | import sample.di.business.service.ProductDao; 8 | 9 | public class ProductDaoImpl implements ProductDao { 10 | // Dao만으로 간단하게 구현하게 위해서 RDB에 접속은 하지 않습니다. 11 | // Map은 RDB대신으로 사용 12 | private Map storage = new HashMap(); 13 | 14 | public Product findByProductName(String name) { 15 | return storage.get(name); 16 | } 17 | 18 | public void addProduct(Product product) { 19 | storage.put(product.getName(), product); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /di-config/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /di-config/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-config/src/test/java/.gitignore -------------------------------------------------------------------------------- /di-config/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-config/src/test/resources/.gitignore -------------------------------------------------------------------------------- /di-javaconfig/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /di-javaconfig/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /di-javaconfig/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | di-javaconfig 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /di-javaconfig/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /di-javaconfig/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /di-javaconfig/ReadMe: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 1.「src/main/java」폴더안의 「sample」패키지의「ProductSampleRun.java」를 선택 3 | 2.마우스 오른쪽 클릭해서「Run As > Java Application」로 실행 4 | 3.결과를 콘솔에서 확인 -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/ProductSampleRun.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | import sample.config.AppConfig; 7 | import sample.di.business.domain.Product; 8 | import sample.di.business.service.ProductService; 9 | 10 | public class ProductSampleRun { 11 | 12 | public static void main(String[] args) { 13 | ProductSampleRun productSampleRun = new ProductSampleRun(); 14 | productSampleRun.execute(); 15 | } 16 | 17 | @SuppressWarnings("resource") 18 | public void execute() { 19 | ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); 20 | ProductService productService = ctx.getBean(ProductService.class); 21 | 22 | productService.addProduct(new Product("ホチキス", 100)); 23 | 24 | Product product = productService.findByProductName("ホチキス"); 25 | System.out.println(product); 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowire; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import sample.di.business.service.ProductServiceImpl; 8 | import sample.di.dataaccess.ProductDaoImpl; 9 | 10 | @Configuration 11 | public class AppConfig { 12 | @Bean(autowire = Autowire.BY_TYPE) 13 | public ProductServiceImpl productServices() { 14 | return new ProductServiceImpl(); 15 | } 16 | 17 | @Bean 18 | public ProductDaoImpl productDao() { 19 | return new ProductDaoImpl(); 20 | } 21 | } -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/di/business/domain/Product.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.domain; 2 | 3 | public class Product { 4 | private String name; 5 | private int price; 6 | 7 | public Product(String name, int price) { 8 | this.name = name; 9 | this.price = price; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Product [name=" + name + ", price=" + price + "]"; 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | final int prime = 31; 28 | int result = 1; 29 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 30 | result = prime * result + price; 31 | return result; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (this == obj) 37 | return true; 38 | if (obj == null) 39 | return false; 40 | if (getClass() != obj.getClass()) 41 | return false; 42 | Product other = (Product) obj; 43 | if (name == null) { 44 | if (other.name != null) 45 | return false; 46 | } else if (!name.equals(other.name)) 47 | return false; 48 | if (price != other.price) 49 | return false; 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/di/business/service/ProductDao.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductDao { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/di/business/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import sample.di.business.domain.Product; 4 | 5 | public interface ProductService { 6 | void addProduct(Product product); 7 | Product findByProductName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/di/business/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.business.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import sample.di.business.domain.Product; 6 | 7 | public class ProductServiceImpl implements ProductService { 8 | @Autowired 9 | private ProductDao productDao; 10 | 11 | public void addProduct(Product product) { 12 | productDao.addProduct(product); 13 | 14 | } 15 | 16 | public Product findByProductName(String name) { 17 | return productDao.findByProductName(name); 18 | } 19 | } -------------------------------------------------------------------------------- /di-javaconfig/src/main/java/sample/di/dataaccess/ProductDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.di.dataaccess; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import sample.di.business.domain.Product; 7 | import sample.di.business.service.ProductDao; 8 | 9 | public class ProductDaoImpl implements ProductDao { 10 | 11 | private Map storage = new HashMap(); 12 | 13 | public Product findByProductName(String name) { 14 | return storage.get(name); 15 | } 16 | 17 | public void addProduct(Product product) { 18 | storage.put(product.getName(), product); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /di-javaconfig/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /di-javaconfig/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-javaconfig/src/test/java/.gitignore -------------------------------------------------------------------------------- /di-javaconfig/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/di-javaconfig/src/test/resources/.gitignore -------------------------------------------------------------------------------- /hibernate/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /hibernate/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hibernate 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /hibernate/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /hibernate/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /hibernate/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 예제의 실행 방법 2 | 3 | 1. sample.Main클래스의 main메서드를 실행하면 Hibernate연계 예제가 실행됩니다. -------------------------------------------------------------------------------- /hibernate/src/main/java/sample/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | @Configuration 11 | public class DataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource(){ 15 | return 16 | new EmbeddedDatabaseBuilder() 17 | .setType(EmbeddedDatabaseType.HSQL) 18 | .addScript("script/table.sql") 19 | .addScript("script/data.sql") 20 | .build(); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /hibernate/src/main/java/sample/hibernate/business/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.hibernate.business.domain; 2 | 3 | import java.util.Date; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.JoinColumn; 9 | import javax.persistence.ManyToOne; 10 | 11 | public class Pet { 12 | private Integer petId; 13 | private String petName; 14 | private Integer price; 15 | private Date birthDate; 16 | 17 | public Integer getPetId() { 18 | return petId; 19 | } 20 | public void setPetId(Integer petId) { 21 | this.petId = petId; 22 | } 23 | public String getPetName() { 24 | return petName; 25 | } 26 | public void setPetName(String petName) { 27 | this.petName = petName; 28 | } 29 | public Integer getPrice() { 30 | return price; 31 | } 32 | public void setPrice(Integer price) { 33 | this.price = price; 34 | } 35 | public Date getBirthDate() { 36 | return birthDate; 37 | } 38 | public void setBirthDate(Date birthDate) { 39 | this.birthDate = birthDate; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /hibernate/src/main/java/sample/hibernate/business/service/PetDao.java: -------------------------------------------------------------------------------- 1 | package sample.hibernate.business.service; 2 | 3 | import java.util.List; 4 | 5 | import sample.hibernate.business.domain.Pet; 6 | 7 | public interface PetDao { 8 | 9 | Pet findById(int petId); 10 | 11 | List findAll(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /hibernate/src/main/java/sample/hibernate/dataaccess/HibernatePetDao.java: -------------------------------------------------------------------------------- 1 | package sample.hibernate.dataaccess; 2 | 3 | import java.util.List; 4 | 5 | import org.hibernate.Session; 6 | import org.hibernate.SessionFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import sample.hibernate.business.domain.Pet; 11 | import sample.hibernate.business.service.PetDao; 12 | 13 | @Repository 14 | public class HibernatePetDao implements PetDao { 15 | 16 | @Autowired 17 | private SessionFactory sf; 18 | 19 | @Override 20 | public Pet findById(int petId) { 21 | Session s = sf.getCurrentSession(); 22 | return (Pet)s.get(Pet.class, petId); 23 | } 24 | 25 | @Override 26 | public List findAll() { 27 | Session s = sf.getCurrentSession(); 28 | return s.createQuery("from Pet").list(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /hibernate/src/main/java/sample/hibernate/dataaccess/Pet.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /hibernate/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | database.url=jdbc:mysql://192.168.115.211/memorarchy?useUnicode=true&characterEncoding=utf8&autoReconnect=true 2 | database.user=ore 3 | database.password=dayo 4 | database.cipherKey=aaaabbbbccccdddd 5 | -------------------------------------------------------------------------------- /hibernate/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.orm.hibernate4.HibernateTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /hibernate/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | insert into PET values(2, '나비', 1, 5000, '2015-01-01'); 2 | insert into PET values(3, '나비', 1, 15000, '2015-01-01'); 3 | insert into PET values(10, '나비', 1, 15000, '2015-01-01'); 4 | insert into PET values(11, '나비', 1, 9000, '2015-01-01'); 5 | insert into PET values(12, '방울', 1, 1500, '2015-01-01'); 6 | 7 | insert into OWNER VALUES (1, '홍길동'); -------------------------------------------------------------------------------- /hibernate/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | create table PET (PET_ID integer primary key, PET_NAME varchar(50), OWNER_ID integer, PRICE integer, BIRTH_DATE date); 2 | create table OWNER (OWNER_ID integer primary key, OWNER_NAME varchar(50)); -------------------------------------------------------------------------------- /hibernate/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/hibernate/src/test/java/.gitignore -------------------------------------------------------------------------------- /hibernate/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/hibernate/src/test/resources/.gitignore -------------------------------------------------------------------------------- /jpa/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /jpa/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /jpa/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jpa 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /jpa/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /jpa/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /jpa/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 예제의 실행 방법 2 | 3 | 1. sample.Main클래스의 main메서드를 실행하면 JPA연계 예제가 실행됩니다. 4 | 5 | 2. sample.JndiMain클래스의 main메서드를 실행하면 JNDI에 등록한 EntityManagerFactory를 사용한 예제가 실행됩니다. -------------------------------------------------------------------------------- /jpa/src/main/java/sample/Main.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | import org.springframework.transaction.PlatformTransactionManager; 7 | import org.springframework.transaction.TransactionStatus; 8 | 9 | import sample.config.DataSourceConfig; 10 | import sample.config.JpaConfig; 11 | import sample.jpa.business.service.PetDao; 12 | 13 | public class Main { 14 | 15 | public static void main(String[] args) { 16 | //Spring의 컨테이너를 생성 17 | //JavaConfig로 Bean을 정의한 경우 18 | ApplicationContext ctx = new AnnotationConfigApplicationContext(DataSourceConfig.class, JpaConfig.class); 19 | 20 | //Spring의 컨테이너를 생성 21 | //XML로 Bean을 정의한 경우 22 | //ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-jpa.xml"); 23 | 24 | //트랜잭션 시작 25 | PlatformTransactionManager t = ctx.getBean(PlatformTransactionManager.class); 26 | TransactionStatus s = t.getTransaction(null); 27 | 28 | PetDao dao = ctx.getBean(PetDao.class); 29 | 30 | System.out.println(dao.findById(12).getPetName()); 31 | 32 | //트랜잭션 커밋 33 | t.commit(s); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | @Configuration 11 | public class DataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource(){ 15 | return 16 | new EmbeddedDatabaseBuilder() 17 | .setType(EmbeddedDatabaseType.HSQL) 18 | .addScript("script/table.sql") 19 | .addScript("script/data.sql") 20 | .build(); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/config/spring-jpa-jndi.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/jpa/business/domain/Owner.java: -------------------------------------------------------------------------------- 1 | package sample.jpa.business.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | public class Owner { 8 | 9 | @Id 10 | private Integer ownerId; 11 | private String ownerName; 12 | 13 | public Integer getOwnerId() { 14 | return ownerId; 15 | } 16 | public void setOwnerId(Integer ownerId) { 17 | this.ownerId = ownerId; 18 | } 19 | public String getOwnerName() { 20 | return ownerName; 21 | } 22 | public void setOwnerName(String ownerName) { 23 | this.ownerName = ownerName; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/jpa/business/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.jpa.business.domain; 2 | 3 | import java.util.Date; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.JoinColumn; 9 | import javax.persistence.ManyToOne; 10 | 11 | @Entity 12 | public class Pet { 13 | @Id 14 | private Integer petId; 15 | private String petName; 16 | @ManyToOne 17 | @JoinColumn(name="owner_id") 18 | private Owner owner; 19 | private Integer price; 20 | private Date birthDate; 21 | 22 | public Integer getPetId() { 23 | return petId; 24 | } 25 | public void setPetId(Integer petId) { 26 | this.petId = petId; 27 | } 28 | public String getPetName() { 29 | return petName; 30 | } 31 | public void setPetName(String petName) { 32 | this.petName = petName; 33 | } 34 | public Integer getPrice() { 35 | return price; 36 | } 37 | public Owner getOwner() { 38 | return owner; 39 | } 40 | public void setOwner(Owner owner) { 41 | this.owner = owner; 42 | } 43 | public void setPrice(Integer price) { 44 | this.price = price; 45 | } 46 | public Date getBirthDate() { 47 | return birthDate; 48 | } 49 | public void setBirthDate(Date birthDate) { 50 | this.birthDate = birthDate; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/jpa/business/service/PetDao.java: -------------------------------------------------------------------------------- 1 | package sample.jpa.business.service; 2 | 3 | import java.util.List; 4 | 5 | import sample.jpa.business.domain.Pet; 6 | 7 | public interface PetDao { 8 | 9 | Pet findById(int petId); 10 | 11 | List findAll(); 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /jpa/src/main/java/sample/jpa/dataaccess/JpaPetDao.java: -------------------------------------------------------------------------------- 1 | package sample.jpa.dataaccess; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | 8 | import org.hibernate.Session; 9 | import org.hibernate.SessionFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Repository; 12 | 13 | import sample.jpa.business.domain.Pet; 14 | import sample.jpa.business.service.PetDao; 15 | 16 | @Repository 17 | public class JpaPetDao implements PetDao { 18 | 19 | @PersistenceContext 20 | private EntityManager em; 21 | 22 | @Override 23 | public Pet findById(int petId) { 24 | return em.find(Pet.class, petId); 25 | } 26 | 27 | @Override 28 | public List findAll() { 29 | return em.createQuery("from Pet").getResultList(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /jpa/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | database.url=jdbc:mysql://192.168.115.211/memorarchy?useUnicode=true&characterEncoding=utf8&autoReconnect=true 2 | database.user=ore 3 | database.password=dayo 4 | database.cipherKey=aaaabbbbccccdddd 5 | -------------------------------------------------------------------------------- /jpa/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.orm.jpa.JpaTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /jpa/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | insert into PET values(2, '나비', 1, 5000, '2015-01-01'); 2 | insert into PET values(3, '나비', 1, 15000, '2015-01-01'); 3 | insert into PET values(10, '나비', 1, 15000, '2015-01-01'); 4 | insert into PET values(11, '나비', 1, 9000, '2015-01-01'); 5 | insert into PET values(12, '방울', 1, 1500, '2015-01-01'); 6 | 7 | insert into OWNER VALUES (1, '홍길동'); -------------------------------------------------------------------------------- /jpa/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | create table PET (PET_ID integer primary key, PET_NAME varchar(50), OWNER_ID integer, PRICE integer, BIRTH_DATE date); 2 | create table OWNER (OWNER_ID integer primary key, OWNER_NAME varchar(50)); -------------------------------------------------------------------------------- /jpa/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/jpa/src/test/java/.gitignore -------------------------------------------------------------------------------- /jpa/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/jpa/src/test/resources/.gitignore -------------------------------------------------------------------------------- /mvc/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /mvc/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /mvc/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /mvc/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /mvc/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/META-INF/spring/beans-webmvc.xml 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /mvc/src/main/java/sample/customer/biz/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package sample.customer.biz.service; 2 | 3 | import sample.customer.biz.domain.Customer; 4 | 5 | import java.util.List; 6 | 7 | public interface CustomerService { 8 | public List findAll(); 9 | 10 | public Customer findById(int id) throws DataNotFoundException; 11 | 12 | public Customer register(Customer customer); 13 | 14 | public void update(Customer customer) throws DataNotFoundException; 15 | 16 | public void delete(int id) throws DataNotFoundException; 17 | } 18 | -------------------------------------------------------------------------------- /mvc/src/main/java/sample/customer/biz/service/DataNotFoundException.java: -------------------------------------------------------------------------------- 1 | package sample.customer.biz.service; 2 | 3 | 4 | public class DataNotFoundException extends Exception { 5 | 6 | public DataNotFoundException() { 7 | } 8 | 9 | public DataNotFoundException(String msg) { 10 | super(msg); 11 | } 12 | 13 | public DataNotFoundException(Throwable th) { 14 | super(th); 15 | } 16 | 17 | public DataNotFoundException(String msg, Throwable th) { 18 | super(msg, th); 19 | } 20 | 21 | private static final long serialVersionUID = 9046514570511590390L; 22 | } 23 | -------------------------------------------------------------------------------- /mvc/src/main/java/sample/customer/config/BizConfig.java: -------------------------------------------------------------------------------- 1 | package sample.customer.config; 2 | 3 | import org.springframework.context.MessageSource; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.support.ReloadableResourceBundleMessageSource; 8 | 9 | @Configuration 10 | @ComponentScan("sample.customer.biz.service") 11 | public class BizConfig { 12 | 13 | @Bean 14 | public MessageSource messageSource() { 15 | ReloadableResourceBundleMessageSource messageSource 16 | = new ReloadableResourceBundleMessageSource(); 17 | messageSource.setBasename("classpath:/META-INF/messages"); 18 | 19 | return messageSource; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mvc/src/main/java/sample/customer/web/controller/CustomerControllerAdvice.java: -------------------------------------------------------------------------------- 1 | package sample.customer.web.controller; 2 | 3 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.WebDataBinder; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.InitBinder; 10 | 11 | import sample.customer.biz.service.DataNotFoundException; 12 | 13 | @Component 14 | @ControllerAdvice(annotations = Controller.class) 15 | public class CustomerControllerAdvice { 16 | 17 | @InitBinder 18 | public void initBinder(WebDataBinder binder) { 19 | binder.registerCustomEditor(String.class, 20 | new StringTrimmerEditor(true)); 21 | } 22 | 23 | @ExceptionHandler(DataNotFoundException.class) 24 | public String handleException() { 25 | return "customer/notfound"; 26 | } 27 | 28 | @ExceptionHandler(Exception.class) 29 | public String handleException(Exception e) { 30 | e.printStackTrace(); 31 | 32 | return "error"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mvc/src/main/resources/META-INF/messages.properties: -------------------------------------------------------------------------------- 1 | errors.datanotfound.customer=\u6307\u5b9a\u3055\u308c\u305fID\u306e\u9867\u5ba2\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002 2 | errors.emailAddress.ng=\u3053\u306eE\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f\u4f7f\u7528\u4e0d\u53ef\u3068\u3057\u3066\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002 3 | 4 | typeMismatch.java.util.Date = {0}\u306fyyyy/MM/dd\u5f62\u5f0f\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002 5 | typeMismatch.java.lang.Integer = {0}\u306f\u6570\u5024\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002 6 | 7 | NotNull = {0}\u306f\u5fc5\u9808\u3067\u3059 8 | Size = {0}\u306f{max}\u6587\u5b57\u4ee5\u5185\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 9 | Pattern = {0}\u3092\u6b63\u3057\u3044\u5f62\u5f0f\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 10 | Max = {0}\u306f{1}\u4ee5\u5185\u306e\u6570\u5024\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 11 | Min = {0}\u306f{1}\u4ee5\u4e0a\u306e\u6570\u5024\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 12 | 13 | 14 | name = \u540d\u524d 15 | address = \u4f4f\u6240 16 | emailAddress = E\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9 17 | birthday = \u8a95\u751f\u65e5 18 | favoriteNumber = \u597d\u304d\u306a\u6570\u5b57 19 | -------------------------------------------------------------------------------- /mvc/src/main/resources/META-INF/spring/beans-biz.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /mvc/src/main/resources/META-INF/spring/beans-webmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /mvc/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/customer/detail.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 4 | 5 | 6 | 7 | 8 | 顧客詳細画面 9 | 10 | 11 |

顧客詳細画面

12 |
13 |
名前
14 |
15 |
Eメールアドレス
16 |
17 |
誕生日
18 |
19 |
好きな数字
20 |
21 |
22 | 23 | 一覧 24 | 25 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/customer/edit/edited.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 4 | 5 | 6 | 7 | 8 | 更新完了 9 | 10 | 11 |

更新完了

12 |
13 |
名前
14 |
15 |
Eメールアドレス
16 |
17 |
誕生日
18 |
19 |
好きな数字
20 |
21 |
22 | 23 | 戻る 24 | 25 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/customer/edit/enter.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | 4 | 5 | 6 | 7 | 入力画面 8 | 9 | 10 |

入力画面

11 | 12 |
13 |
名前
14 |
15 | 16 | 17 |
18 |
Eメールアドレス
19 |
20 | 21 | 22 | 23 |
24 |
誕生日
25 |
26 | 27 | 28 |
29 |
好きな数字
30 |
31 | 32 | 33 |
34 |
35 | 38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/customer/edit/review.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 4 | 5 | 6 | 7 | 8 | 確認画面 9 | 10 | 11 |

確認画面

12 |
13 |
14 |
名前
15 |
16 |
Eメールアドレス
17 |
18 |
誕生日
19 |
20 |
好きな数字
21 |
22 |
23 | 24 | 25 |
26 | 27 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/customer/notfound.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 3 | 4 | 5 | 6 | 7 | 指定された顧客は見つかりません 8 | 9 | 10 |

指定された顧客は見つかりません

11 | 12 | 一覧画面へ戻る 13 | 14 | -------------------------------------------------------------------------------- /mvc/src/main/webapp/WEB-INF/views/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 3 | 4 | 5 | 6 | 7 | 例外発生 8 | 9 | 10 |
11 |
例外クラス
12 |
${exception.getClass().name}
13 |
メッセージ
14 |
${exception.message}
15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /mvc/src/test/java/sample/customer/biz/domain/FindCustomerByIdMain.java: -------------------------------------------------------------------------------- 1 | package sample.customer.biz.domain; 2 | 3 | import org.apache.commons.httpclient.HttpClient; 4 | import org.apache.commons.httpclient.methods.GetMethod; 5 | 6 | public class FindCustomerByIdMain { 7 | private static String CUSTOMER_FIND_URL 8 | = "http://localhost:8080/mvc/api/customer/3"; 9 | 10 | public static void main(String[] args) throws Exception { 11 | HttpClient client = new HttpClient(); 12 | 13 | GetMethod method = new GetMethod(CUSTOMER_FIND_URL); 14 | client.executeMethod(method); 15 | 16 | System.out.println(method.getStatusCode()); 17 | System.out.println(method.getResponseBodyAsString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mvc/src/test/java/sample/customer/biz/domain/RegisterCustomerMain.java: -------------------------------------------------------------------------------- 1 | package sample.customer.biz.domain; 2 | 3 | import org.apache.commons.httpclient.HttpClient; 4 | import org.apache.commons.httpclient.methods.PostMethod; 5 | import org.apache.commons.httpclient.methods.StringRequestEntity; 6 | 7 | public class RegisterCustomerMain { 8 | 9 | private static String CUSTOMER_REGISTER_URL 10 | = "http://localhost:8080/mvc/api/customer"; 11 | 12 | public static void main(String[] args) throws Exception { 13 | HttpClient client = new HttpClient(); 14 | 15 | PostMethod method = new PostMethod(CUSTOMER_REGISTER_URL); 16 | method.setRequestEntity( 17 | new StringRequestEntity(xml(), "text/xml", "UTF-8")); 18 | client.executeMethod(method); 19 | 20 | System.out.println(method.getStatusCode()); 21 | System.out.println(method.getResponseBodyAsString()); 22 | } 23 | 24 | private static String xml() { 25 | StringBuilder sb = new StringBuilder(); 26 | sb.append("") 27 | .append(" 追加郎") 28 | .append(" tsuika@aa.bb.cc") 29 | .append(" 1985-03-21T00:00:00+09:00") 30 | .append(" 7") 31 | .append(""); 32 | 33 | return sb.toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mybatis/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /mybatis/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mybatis 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /mybatis/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /mybatis/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /mybatis/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 예제의 실행 방법 2 | 3 | 1. sample.Main클래스의 main메서드를 실행하면 MyBatis연계 예제가 실행됩니다. 4 | 2. sample.MainForMapper클래스의 main메서드를 실행하면 MyBatis연계 예제(Mapper를 사용)가 실행됩니다. -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/Main.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | import org.springframework.transaction.PlatformTransactionManager; 9 | import org.springframework.transaction.TransactionStatus; 10 | 11 | import sample.config.DataSourceConfig; 12 | import sample.config.MyBatisConfig; 13 | import sample.mybatis.business.domain.Pet; 14 | import sample.mybatis.business.service.PetDao; 15 | 16 | public class Main { 17 | 18 | public static void main(String[] args) { 19 | //Spring의 컨테이너를 생성 20 | //JavaConfig로 Bean을 정의한 경우 21 | ApplicationContext ctx = new AnnotationConfigApplicationContext(DataSourceConfig.class, MyBatisConfig.class); 22 | 23 | //Spring의 컨테이너를 생성 24 | //XML로 Bean을 정의한 경우 25 | //ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-mybatis.xml"); 26 | 27 | 28 | PetDao dao = ctx.getBean(PetDao.class); 29 | 30 | List list = dao.findAll(); 31 | 32 | System.out.println(list.get(0).getPetName()); 33 | 34 | Pet p = dao.findById(12); 35 | System.out.println(p.getPetName()); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/MainForMapper.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | import org.springframework.transaction.PlatformTransactionManager; 9 | import org.springframework.transaction.TransactionStatus; 10 | 11 | import sample.config.DataSourceConfig; 12 | import sample.config.MyBatisConfig; 13 | import sample.config.MyBatisConfigForMapper; 14 | import sample.mybatis.business.domain.Pet; 15 | import sample.mybatis.business.service.PetDao; 16 | 17 | public class MainForMapper { 18 | 19 | public static void main(String[] args) { 20 | //Spring의 컨테이너를 생성 21 | //JavaConfig로 Bean을 정의한 경우 22 | ApplicationContext ctx = new AnnotationConfigApplicationContext(DataSourceConfig.class, MyBatisConfigForMapper.class); 23 | 24 | //Spring의 컨테이너를 생성 25 | //XML로 Bean을 정의한 경우 26 | //ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-mybatis-mapper.xml"); 27 | 28 | PetDao dao = ctx.getBean(PetDao.class); 29 | 30 | List list = dao.findAll(); 31 | 32 | System.out.println(list.get(0).getPetName()); 33 | 34 | 35 | Pet p = dao.findById(12); 36 | System.out.println(p.getPetName()); 37 | 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | @Configuration 11 | public class DataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource(){ 15 | return 16 | new EmbeddedDatabaseBuilder() 17 | .setType(EmbeddedDatabaseType.HSQL) 18 | .addScript("script/table.sql") 19 | .addScript("script/data.sql") 20 | .build(); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/config/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/mybatis/business/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.mybatis.business.domain; 2 | 3 | import java.util.Date; 4 | 5 | 6 | public class Pet { 7 | private Integer petId; 8 | private String petName; 9 | private Integer price; 10 | private Date birthDate; 11 | 12 | public Integer getPetId() { 13 | return petId; 14 | } 15 | public void setPetId(Integer petId) { 16 | this.petId = petId; 17 | } 18 | public String getPetName() { 19 | return petName; 20 | } 21 | public void setPetName(String petName) { 22 | this.petName = petName; 23 | } 24 | public Integer getPrice() { 25 | return price; 26 | } 27 | public void setPrice(Integer price) { 28 | this.price = price; 29 | } 30 | public Date getBirthDate() { 31 | return birthDate; 32 | } 33 | public void setBirthDate(Date birthDate) { 34 | this.birthDate = birthDate; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/mybatis/business/service/PetDao.java: -------------------------------------------------------------------------------- 1 | package sample.mybatis.business.service; 2 | 3 | import java.util.List; 4 | 5 | import sample.mybatis.business.domain.Pet; 6 | 7 | public interface PetDao { 8 | 9 | Pet findById(int petId); 10 | 11 | List findAll(); 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/mybatis/dataaccess/MyBatisPetDao.java: -------------------------------------------------------------------------------- 1 | package sample.mybatis.dataaccess; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import sample.mybatis.business.domain.Pet; 10 | import sample.mybatis.business.service.PetDao; 11 | 12 | @Repository 13 | public class MyBatisPetDao implements PetDao { 14 | 15 | @Autowired 16 | private SqlSession ss; 17 | 18 | @Override 19 | public Pet findById(int petId) { 20 | return ss.selectOne("sample.mybatis.business.service.PetDao.findById", petId); 21 | } 22 | 23 | @Override 24 | public List findAll() { 25 | return ss.selectList("sample.mybatis.business.service.PetDao.findAll"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mybatis/src/main/java/sample/mybatis/dataaccess/pet.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /mybatis/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | database.url=jdbc:mysql://192.168.115.211/memorarchy?useUnicode=true&characterEncoding=utf8&autoReconnect=true 2 | database.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy 3 | database.user=ore 4 | database.password=dayo 5 | database.cipherKey=aaaabbbbccccdddd 6 | -------------------------------------------------------------------------------- /mybatis/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.jdbc.datasource.DataSourceTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /mybatis/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | insert into PET values(2, '나비', 1, 5000, '2015-01-01'); 2 | insert into PET values(3, '나비', 1, 15000, '2015-01-01'); 3 | insert into PET values(10, '나비', 1, 15000, '2015-01-01'); 4 | insert into PET values(11, '나비', 1, 9000, '2015-01-01'); 5 | insert into PET values(12, '방울', 1, 1500, '2015-01-01'); 6 | 7 | insert into OWNER VALUES (1, '홍길동'); -------------------------------------------------------------------------------- /mybatis/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | create table PET (PET_ID integer primary key, PET_NAME varchar(50), OWNER_ID integer, PRICE integer, BIRTH_DATE date); 2 | create table OWNER (OWNER_ID integer primary key, OWNER_NAME varchar(50)); -------------------------------------------------------------------------------- /mybatis/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/mybatis/src/test/java/.gitignore -------------------------------------------------------------------------------- /mybatis/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/mybatis/src/test/resources/.gitignore -------------------------------------------------------------------------------- /security/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /security/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /security/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /security/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /security/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /security/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /security/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /security/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /security/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /security/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /security/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/resources/META-INF/spring/beans-security-jdbc.xml 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /security/src/main/java/sample/security/authentication/SampleUser.java: -------------------------------------------------------------------------------- 1 | package sample.security.authentication; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.userdetails.User; 7 | 8 | public class SampleUser extends User { 9 | 10 | private String fullName; 11 | 12 | private String deptName; 13 | 14 | public SampleUser(String username, String password, 15 | Collection authorities) { 16 | super(username, password, authorities); 17 | } 18 | 19 | public String getFullName() { 20 | return fullName; 21 | } 22 | 23 | public String getDeptName() { 24 | return deptName; 25 | } 26 | 27 | public void setFullName(String fullName) { 28 | this.fullName = fullName; 29 | } 30 | 31 | public void setDeptName(String deptName) { 32 | this.deptName = deptName; 33 | } 34 | 35 | private static final long serialVersionUID = 5869301720811314860L; 36 | } 37 | -------------------------------------------------------------------------------- /security/src/main/java/sample/security/config/DataAccessMockConfig.java: -------------------------------------------------------------------------------- 1 | package sample.security.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | @Configuration 11 | public class DataAccessMockConfig { 12 | 13 | @Bean 14 | public DataSource authDataSource() { 15 | return new EmbeddedDatabaseBuilder() 16 | .setType(EmbeddedDatabaseType.H2) 17 | .addScript("classpath:/META-INF/db/ddl.sql") 18 | .addScript("classpath:/META-INF/db/dml.sql") 19 | .build(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /security/src/main/resources/META-INF/db/ddl.sql: -------------------------------------------------------------------------------- 1 | drop table if exists T_USER_ROLE ; 2 | drop table if exists T_USER; 3 | drop table if exists T_ROLE; 4 | 5 | create table T_ROLE 6 | ( 7 | ID BIGINT primary key, 8 | ROLE_NAME varchar(100) not null, 9 | DESCRIPTION varchar(100) not null 10 | ) 11 | ; 12 | 13 | create table T_USER 14 | ( 15 | ID BIGINT primary key, 16 | LOGIN_ID VARCHAR(20) not null, 17 | PASSWORD VARCHAR(200) not null, 18 | FULL_NAME VARCHAR(100) not null, 19 | DEPT_NAME VARCHAR(100) 20 | ) 21 | ; 22 | 23 | create table T_USER_ROLE 24 | ( 25 | USER_ID BIGINT, 26 | ROLE_ID BIGINT, 27 | primary key(USER_ID, ROLE_ID) 28 | ) 29 | ; -------------------------------------------------------------------------------- /security/src/main/resources/META-INF/db/dml.sql: -------------------------------------------------------------------------------- 1 | delete from T_USER_ROLE; 2 | delete from T_ROLE; 3 | delete from T_USER; 4 | 5 | insert into T_ROLE values(1, 'ROLE_USER', '일반 롤'); 6 | insert into T_ROLE values(2, 'ROLE_ADMIN', '관리 롤'); 7 | 8 | insert into T_USER values(1, 'user', '$2a$10$nodSZsM7Lyi34l3/YEg61uTVDRIgH.DkM/WF4AM0BKTCGINBOnFOm', '사용자1', '개발부'); 9 | insert into T_USER values(2, 'admin', '$2a$10$0VRu6ZC4zcuXZiS34AaPF.gDcbq25Z5lX01gnf97iBNdl4WeCbCXC', '사용자2', '관리부'); 10 | 11 | insert into T_USER_ROLE values(1, 1); 12 | insert into T_USER_ROLE values(2, 2); 13 | -------------------------------------------------------------------------------- /security/src/main/resources/META-INF/spring/beans-dataaccess-mock.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /security/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /security/src/main/webapp/accessDenied.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 4 | 5 | 6 | 7 | 8 | 9 | 10 |

액세스 거부

11 | 액세스가 거부되었습니다. 12 | 13 | 14 | -------------------------------------------------------------------------------- /security/src/main/webapp/admin/admin.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 |

관리자 전용 페이지

9 | 관리자 전용 페이지입니다.
10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /security/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

로그인 페이지

12 | 13 | 로그인 에러입니다.
14 | 예외 타입:${SPRING_SECURITY_LAST_EXCEPTION.getClass().name}
15 | 메시지:${SPRING_SECURITY_LAST_EXCEPTION.message}
16 | 17 |
18 |
19 | 20 |
21 |
22 | 로그인 ID 23 |
24 |
25 | 26 |
27 |
28 | 패스워드 29 |
30 |
31 | 32 |
33 |
34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /security/src/main/webapp/top.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" %> 2 | <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 로그인 13 | 14 | 15 | 16 | 로그인 유저:${user.username} 17 | 18 |

톱페이지

19 | 톱 페이지입니다. 20 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /security/src/main/webapp/user/user.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html; charset=UTF-8" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 |

일반 사용자용 페이지

9 | 일반 사용자용 페이지입니다.
10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /springdatajpa/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /springdatajpa/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springdatajpa 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /springdatajpa/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /springdatajpa/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springdatajpa/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 3 | 1. sample.Main클래스의 main메서드를 실행하면, Spring Data Jpa를 사용한 여러가지 예제가 실행됩니다. 4 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import sample.springdatajpa.dataaccess.PetDaoImpl; 7 | 8 | @Configuration 9 | public class AppConfig { 10 | 11 | @Bean 12 | public PetDaoImpl petDaoImpl() { 13 | return new PetDaoImpl(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 8 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 9 | 10 | @Configuration 11 | public class DataSourceConfig { 12 | 13 | @Bean 14 | public DataSource dataSource(){ 15 | return 16 | new EmbeddedDatabaseBuilder() 17 | .setType(EmbeddedDatabaseType.HSQL) 18 | .addScript("script/table.sql") 19 | .addScript("script/data.sql") 20 | .build(); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/springdatajpa/business/domain/Owner.java: -------------------------------------------------------------------------------- 1 | package sample.springdatajpa.business.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | public class Owner { 8 | 9 | @Id 10 | private Integer ownerId; 11 | private String ownerName; 12 | 13 | public Integer getOwnerId() { 14 | return ownerId; 15 | } 16 | public void setOwnerId(Integer ownerId) { 17 | this.ownerId = ownerId; 18 | } 19 | public String getOwnerName() { 20 | return ownerName; 21 | } 22 | public void setOwnerName(String ownerName) { 23 | this.ownerName = ownerName; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/springdatajpa/business/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.springdatajpa.business.domain; 2 | 3 | import java.util.Date; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.JoinColumn; 9 | import javax.persistence.ManyToOne; 10 | 11 | @Entity 12 | public class Pet { 13 | @Id 14 | private Integer petId; 15 | private String petName; 16 | @ManyToOne 17 | @JoinColumn(name="owner_id") 18 | private Owner owner; 19 | private Integer price; 20 | private Date birthDate; 21 | 22 | public Integer getPetId() { 23 | return petId; 24 | } 25 | public void setPetId(Integer petId) { 26 | this.petId = petId; 27 | } 28 | public String getPetName() { 29 | return petName; 30 | } 31 | public void setPetName(String petName) { 32 | this.petName = petName; 33 | } 34 | public Integer getPrice() { 35 | return price; 36 | } 37 | public Owner getOwner() { 38 | return owner; 39 | } 40 | public void setOwner(Owner owner) { 41 | this.owner = owner; 42 | } 43 | public void setPrice(Integer price) { 44 | this.price = price; 45 | } 46 | public Date getBirthDate() { 47 | return birthDate; 48 | } 49 | public void setBirthDate(Date birthDate) { 50 | this.birthDate = birthDate; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/springdatajpa/business/service/PetDao.java: -------------------------------------------------------------------------------- 1 | package sample.springdatajpa.business.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import sample.springdatajpa.business.domain.Pet; 12 | 13 | @Repository 14 | public interface PetDao extends JpaRepository, PetDaoCustom { 15 | List findByPetName(String petName); 16 | List findByPetNameAndPriceLessThanEqual(String petName, int price); 17 | 18 | @Query("select p from Pet p where p.owner.ownerName = :ownerName") 19 | List findByOwnerName(@Param("ownerName") String ownerName); 20 | 21 | @Modifying 22 | @Query("update Pet p set p.price = ?1 where p.petName = ?2") 23 | int updatePetPrice(Integer price, String petName); 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/springdatajpa/business/service/PetDaoCustom.java: -------------------------------------------------------------------------------- 1 | package sample.springdatajpa.business.service; 2 | 3 | 4 | public interface PetDaoCustom { 5 | void foo(); 6 | } 7 | -------------------------------------------------------------------------------- /springdatajpa/src/main/java/sample/springdatajpa/dataaccess/PetDaoImpl.java: -------------------------------------------------------------------------------- 1 | package sample.springdatajpa.dataaccess; 2 | 3 | import sample.springdatajpa.business.service.PetDaoCustom; 4 | 5 | public class PetDaoImpl implements PetDaoCustom { 6 | @Override 7 | public void foo() { 8 | System.out.println("foo!"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /springdatajpa/src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | database.url=jdbc:mysql://127.0.0.1/memorarchy?useUnicode=true&characterEncoding=utf8&autoReconnect=true 2 | database.user=hong 3 | database.password=hong 4 | database.cipherKey=aaaabbbbccccdddd 5 | -------------------------------------------------------------------------------- /springdatajpa/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.orm.jpa.JpaTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /springdatajpa/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | insert into PET values(1, '발라리', 1, 5000, '2015-01-01'); 2 | insert into PET values(2, '나비', 2, 5000, '2015-01-01'); 3 | insert into PET values(3, '나비', 1, 15000, '2015-01-01'); 4 | insert into PET values(10, '나비3', 1, 15000, '2015-01-01'); 5 | insert into PET values(11, '나비4', 2, 9000, '2015-01-01'); 6 | insert into PET values(12, '나비5', 1, 1500, '2015-01-01'); 7 | 8 | insert into OWNER VALUES (1, '홍길동'); 9 | insert into OWNER VALUES (2, '김삿갓'); -------------------------------------------------------------------------------- /springdatajpa/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | create table PET (PET_ID integer primary key, PET_NAME varchar(50), OWNER_ID integer, PRICE integer, BIRTH_DATE date); 2 | create table OWNER (OWNER_ID integer primary key, OWNER_NAME varchar(50)); -------------------------------------------------------------------------------- /springdatajpa/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/springdatajpa/src/test/java/.gitignore -------------------------------------------------------------------------------- /springdatajpa/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/springdatajpa/src/test/resources/.gitignore -------------------------------------------------------------------------------- /springjdbc/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /springjdbc/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springjdbc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /springjdbc/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /springjdbc/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springjdbc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 3 | 1. sample.ExecuteSqlMain클래스의 main메서드를 실행하면, SpringJDBC를 사용한 다양한 예제가 실행됩니다. 4 | 5 | 2. sample.JndiMain클래스의 main메서드를 실행하면, JNDI경유의 데이터소스를 취득하는예제가 실행됩니다. -------------------------------------------------------------------------------- /springjdbc/src/main/java/sample/config/JndiConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import javax.sql.DataSource; 7 | 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.PropertySource; 12 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 13 | 14 | @Configuration 15 | @PropertySource("jndi.properties") 16 | public class JndiConfig { 17 | 18 | 19 | @Value("${jndi.datasource}") 20 | private String jndiName; 21 | 22 | @Bean 23 | public static PropertySourcesPlaceholderConfigurer propertyConfig() { 24 | return new PropertySourcesPlaceholderConfigurer(); 25 | } 26 | 27 | @Bean 28 | public DataSource dataSource() throws NamingException { 29 | Context ctx = new InitialContext(); 30 | return (DataSource)ctx.lookup(jndiName); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springjdbc/src/main/java/sample/config/TemplateConfig.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Import; 9 | import org.springframework.context.annotation.PropertySource; 10 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 11 | import org.springframework.core.io.ClassPathResource; 12 | import org.springframework.jdbc.core.JdbcTemplate; 13 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 14 | 15 | @Configuration 16 | public class TemplateConfig { 17 | 18 | @Autowired 19 | private DataSource dataSource; 20 | @Bean 21 | public JdbcTemplate jdbcTemplate() { 22 | JdbcTemplate t = new JdbcTemplate(); 23 | t.setDataSource(dataSource); 24 | return t; 25 | 26 | } 27 | @Bean 28 | public NamedParameterJdbcTemplate npJdbcTemplate() { 29 | return new NamedParameterJdbcTemplate(dataSource); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springjdbc/src/main/java/sample/config/spring-jndi.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /springjdbc/src/main/java/sample/springjdbc/business/domain/Owner.java: -------------------------------------------------------------------------------- 1 | package sample.springjdbc.business.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Owner { 7 | 8 | private String ownerName; 9 | private List petList = new ArrayList(); 10 | 11 | public String getOwnerName() { 12 | return ownerName; 13 | } 14 | public void setOwnerName(String ownerName) { 15 | this.ownerName = ownerName; 16 | } 17 | public List getPetList() { 18 | return petList; 19 | } 20 | public void setPetList(List petList) { 21 | this.petList = petList; 22 | } 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springjdbc/src/main/java/sample/springjdbc/business/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.springjdbc.business.domain; 2 | 3 | import java.util.Date; 4 | 5 | 6 | public class Pet { 7 | 8 | private Integer petId; 9 | private String petName; 10 | private String ownerName; 11 | private Integer price; 12 | private Date birthDate; 13 | 14 | 15 | public Integer getPetId() { 16 | return petId; 17 | } 18 | public void setPetId(Integer petId) { 19 | this.petId = petId; 20 | } 21 | public String getPetName() { 22 | return petName; 23 | } 24 | public void setPetName(String petName) { 25 | this.petName = petName; 26 | } 27 | public String getOwnerName() { 28 | return ownerName; 29 | } 30 | public void setOwnerName(String ownerName) { 31 | this.ownerName = ownerName; 32 | } 33 | 34 | 35 | public Date getBirthDate() { 36 | return birthDate; 37 | 38 | } 39 | 40 | public void setBirthDate(Date birthDate) { 41 | this.birthDate = birthDate; 42 | } 43 | 44 | public Integer getPrice() { 45 | return price; 46 | } 47 | 48 | public void setPrice(Integer price) { 49 | this.price = price; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /springjdbc/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=org.hsqldb.jdbc.JDBCDriver 2 | jdbc.url=jdbc:hsqldb:mem:sample 3 | jdbc.username=sa 4 | jdbc.password= 5 | jdbc.maxPoolSize=20 6 | -------------------------------------------------------------------------------- /springjdbc/src/main/resources/jndi.properties: -------------------------------------------------------------------------------- 1 | jndi.datasource=jdbc/MyDataSource -------------------------------------------------------------------------------- /springjdbc/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.jdbc.datasource.DataSourceTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /springjdbc/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO OWNER (OWNER_NAME) VALUES ('owner02'); 2 | INSERT INTO OWNER (OWNER_NAME) VALUES ('owner03'); 3 | INSERT INTO OWNER (OWNER_NAME) VALUES ('홍길동'); 4 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (1, '나비', '홍길동', 1000, '2015-01-01'); 5 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (2, '발바리', 'owner002', 2000, '2015-01-01'); 6 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (3, 'aaa', 'owner003', 3000, '2015-01-01'); 7 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (4, 'bbb', 'owner004', 4000, '2015-01-01'); 8 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (5, 'ccc', 'owner005', 5000, '2015-01-01'); 9 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (6, 'ddd', 'owner02', 6000, '2015-01-01'); 10 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (7, '치와와', '홍길동', 2000, '2015-01-01'); 11 | 12 | -------------------------------------------------------------------------------- /springjdbc/src/main/resources/script/proc.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE CALC_PET_PRICE(IN IN_PET_ID INT, OUT OUT_PRICE INT) 2 | READS SQL DATA 3 | BEGIN ATOMIC 4 | DECLARE genka INT; 5 | SET (genka) = (SELECT PRICE FROM PET WHERE PET_ID=IN_PET_ID); 6 | SET (OUT_PRICE) = (genka * 1.08); 7 | END 8 | / -------------------------------------------------------------------------------- /springjdbc/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE OWNER ( 2 | OWNER_NAME VARCHAR(100) NOT NULL 3 | ); 4 | CREATE TABLE PET ( 5 | PET_ID INT NOT NULL, 6 | PET_NAME VARCHAR(100), 7 | OWNER_NAME VARCHAR(100), 8 | PRICE INT, 9 | BIRTH_DATE DATE 10 | ); -------------------------------------------------------------------------------- /springjdbc/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/springjdbc/src/test/java/.gitignore -------------------------------------------------------------------------------- /springjdbc/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/springjdbc/src/test/resources/.gitignore -------------------------------------------------------------------------------- /transaction/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /transaction/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | transaction 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /transaction/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /transaction/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | #Tue Apr 03 09:14:39 JST 2012 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | resolveWorkspaceProjects=true 5 | version=1 6 | -------------------------------------------------------------------------------- /transaction/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ***예제 실행 방법*** 2 | 3 | 1. sample.TranByFileMain클래스의 main메서드를 실행하면, Bean정의 파일을 사용한 선언적 트랜잭션 예제가 실행됩니다. 4 | 5 | 2. sample.TranByAnnotationMain클래스의 main메서드를 실행하면, 애노테이션을 사용한 선언적 트랜잭션의 예제(유효화를 Bean정의파일로 함)가 실행됩니다. 6 | 7 | 3. sample.TranByJavaConfigMain클래스의 main메서드를 실행하면, 애노테이션을 실행하면 선언적 트랜잭션의 예제(유효화를 JavaConfig로 함)가 실행됩니다. 8 | 9 | 4. sample.TranByProgrammaticMain클래스의 main메서드를 실행하면, 명시적 트랜잭션의 예제가 실행됩니다. 10 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/TranByAnnotationMain.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | import java.util.Date; 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import sample.biz.domain.Pet; 8 | import sample.biz.service.PetService; 9 | 10 | public class TranByAnnotationMain { 11 | 12 | public static void main(String[] args) { 13 | ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-tranByAnnotation.xml"); 14 | PetService petService = ctx.getBean(PetService.class); 15 | Pet pet = new Pet(); 16 | pet.setPetId(1); 17 | pet.setPetName("나비"); 18 | pet.setOwnerName("홍길동"); 19 | pet.setPrice(10000); 20 | pet.setBirthDate(new Date()); 21 | 22 | petService.updatePet(pet); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/TranByFileMain.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | import java.util.Date; 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import sample.biz.domain.Pet; 8 | import sample.biz.service.PetService; 9 | 10 | public class TranByFileMain { 11 | 12 | public static void main(String[] args) { 13 | ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-tranByFile.xml"); 14 | PetService petService = ctx.getBean(PetService.class); 15 | Pet pet = new Pet(); 16 | pet.setPetId(1); 17 | pet.setPetName("나비"); 18 | pet.setOwnerName("홍길동"); 19 | pet.setPrice(10000); 20 | pet.setBirthDate(new Date()); 21 | 22 | petService.updatePet(pet); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/TranByJavaConfigMain.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | import java.util.Date; 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 6 | import org.springframework.context.support.ClassPathXmlApplicationContext; 7 | 8 | import sample.biz.domain.Pet; 9 | import sample.biz.service.PetService; 10 | import sample.config.TransactionConfig; 11 | 12 | public class TranByJavaConfigMain { 13 | 14 | public static void main(String[] args) { 15 | ApplicationContext ctx = new AnnotationConfigApplicationContext(TransactionConfig.class); 16 | PetService petService = ctx.getBean(PetService.class); 17 | Pet pet = new Pet(); 18 | pet.setPetId(1); 19 | pet.setPetName("나비"); 20 | pet.setOwnerName("홍길동"); 21 | pet.setPrice(10000); 22 | pet.setBirthDate(new Date()); 23 | 24 | petService.updatePet(pet); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/TranByProgrammaticMain.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | import java.util.Date; 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import sample.biz.domain.Pet; 8 | import sample.biz.service.PetService; 9 | 10 | public class TranByProgrammaticMain { 11 | 12 | public static void main(String[] args) { 13 | ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/config/spring-tranByProgrammatic.xml"); 14 | PetService petService = ctx.getBean(PetService.class); 15 | Pet pet = new Pet(); 16 | pet.setPetId(1); 17 | pet.setPetName("나비"); 18 | pet.setOwnerName("홍길동"); 19 | pet.setPrice(10000); 20 | pet.setBirthDate(new Date()); 21 | 22 | petService.updatePetProgrammaticTransaction2(pet); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/biz/dao/PetDao.java: -------------------------------------------------------------------------------- 1 | package sample.biz.dao; 2 | 3 | import sample.biz.domain.Pet; 4 | 5 | public interface PetDao { 6 | 7 | void updatePet(Pet pet); 8 | } 9 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/biz/domain/Owner.java: -------------------------------------------------------------------------------- 1 | package sample.biz.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Owner { 7 | 8 | private String ownerName; 9 | private List petList = new ArrayList(); 10 | public String getOwnerName() { 11 | return ownerName; 12 | } 13 | public void setOwnerName(String ownerName) { 14 | this.ownerName = ownerName; 15 | } 16 | public List getPetList() { 17 | return petList; 18 | } 19 | public void setPetList(List petList) { 20 | this.petList = petList; 21 | } 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/biz/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package sample.biz.domain; 2 | 3 | import java.util.Date; 4 | 5 | 6 | 7 | public class Pet { 8 | 9 | private int petId; 10 | private String petName; 11 | private String ownerName; 12 | private int price; 13 | private Date birthDate; 14 | 15 | public Date getBirthDate() { 16 | return birthDate; 17 | } 18 | 19 | public void setBirthDate(Date birthDate) { 20 | this.birthDate = birthDate; 21 | } 22 | 23 | public int getPrice() { 24 | return price; 25 | } 26 | 27 | public void setPrice(int price) { 28 | this.price = price; 29 | } 30 | 31 | public Pet() {} 32 | 33 | public Pet(int petId, String petName) { 34 | this.petId = petId; 35 | this.petName = petName; 36 | } 37 | 38 | public int getPetId() { 39 | return petId; 40 | } 41 | public void setPetId(int petId) { 42 | this.petId = petId; 43 | } 44 | public String getPetName() { 45 | return petName; 46 | } 47 | public void setPetName(String petName) { 48 | this.petName = petName; 49 | } 50 | public String getOwnerName() { 51 | return ownerName; 52 | } 53 | public void setOwnerName(String ownerName) { 54 | this.ownerName = ownerName; 55 | } 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/biz/exception/BussinessException.java: -------------------------------------------------------------------------------- 1 | package sample.biz.exception; 2 | 3 | public class BussinessException extends RuntimeException { 4 | 5 | 6 | } 7 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/biz/service/PetService.java: -------------------------------------------------------------------------------- 1 | package sample.biz.service; 2 | 3 | import sample.biz.domain.Pet; 4 | 5 | public interface PetService { 6 | void updatePet(Pet pet); 7 | void updatePetProgrammaticTransaction(Pet pet); 8 | void updatePetProgrammaticTransaction2(Pet pet); 9 | } 10 | -------------------------------------------------------------------------------- /transaction/src/main/java/sample/dao/PetDaoSpringJdbc.java: -------------------------------------------------------------------------------- 1 | package sample.dao; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.jdbc.core.JdbcTemplate; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import sample.biz.dao.PetDao; 8 | import sample.biz.domain.Pet; 9 | 10 | @Repository 11 | public class PetDaoSpringJdbc implements PetDao { 12 | @Autowired 13 | private JdbcTemplate jdbcTemplate; 14 | public void updatePet(Pet pet) { 15 | jdbcTemplate.update( 16 | "UPDATE PET SET PET_NAME=?, OWNER_NAME=?, PRICE=?, BIRTH_DATE=? WHERE PET_ID=?" 17 | , pet.getPetName(), pet.getOwnerName(), pet.getPrice(), pet.getBirthDate(), pet.getPetId()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /transaction/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=WARN, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=[%p:%C{1}:%L:]%m%n 9 | 10 | log4j.logger.org.springframework.jdbc.datasource.DataSourceTransactionManager=DEBUG 11 | -------------------------------------------------------------------------------- /transaction/src/main/resources/script/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO OWNER (OWNER_NAME) VALUES ('owner02'); 2 | INSERT INTO OWNER (OWNER_NAME) VALUES ('owner03'); 3 | INSERT INTO OWNER (OWNER_NAME) VALUES ('홍길동'); 4 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (1, '나비', '홍길동', 1000, '2015-01-01'); 5 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (2, '발바리', 'owner002', 2000, '2015-01-01'); 6 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (3, 'aaa', 'owner003', 3000, '2015-01-01'); 7 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (4, 'bbb', 'owner004', 4000, '2015-01-01'); 8 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (5, 'ccc', 'owner005', 5000, '2015-01-01'); 9 | INSERT INTO PET (PET_ID, PET_NAME, OWNER_NAME, PRICE, BIRTH_DATE) VALUES (6, 'ddd', 'owner02', 6000, '2015-01-01'); 10 | 11 | -------------------------------------------------------------------------------- /transaction/src/main/resources/script/table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE OWNER ( 2 | OWNER_NAME VARCHAR(100) NOT NULL 3 | ); 4 | CREATE TABLE PET ( 5 | PET_ID INT NOT NULL, 6 | PET_NAME VARCHAR(100), 7 | OWNER_NAME VARCHAR(100), 8 | PRICE INT, 9 | BIRTH_DATE DATE 10 | ); -------------------------------------------------------------------------------- /transaction/src/test/java/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/transaction/src/test/java/.gitignore -------------------------------------------------------------------------------- /transaction/src/test/resources/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minsoojun/Spring4/d10a868d76e73e863f82b5c5c2fb5af940d3d6fa/transaction/src/test/resources/.gitignore --------------------------------------------------------------------------------