Spring Boot + Spring Integration ã§ãããã試ãã¦ã¿ã ( ãã®ï¼ )( ç£è¦ãã¦ãããã£ã¬ã¯ããªã«ç½®ããã Excel ãã¡ã¤ã«ã®ãã¼ã¿ã DB ã«ç»é²ãã â å¦çãçµãã£ãã Excel ãã¡ã¤ã«ãåé¤ï¼ç§»åããï¼ )
æ¦è¦
è¨äºä¸è¦§ã¯ãã¡ãã§ãã
åç §ãããµã¤ãã»æ¸ç±
ç®æ¬¡
- user_info, user_role ãã¼ãã«ã«ç»é²ããå¦çãå®è£ ãã
- ãªã transactionManager Bean ãèªåçæãããªãã£ãã®ãï¼
- transactionManager Bean ãçæãã
- å度 UserInfoServiceTest#loadUserInfoFromExcel ãã¹ãã¡ã½ãããå®è¡ãã
- FileProcessor#process ãã UserInfoService#loadUserInfoFromExcel ãå¼ã³åºãããå®è£ ãã
- åä½ç¢ºèª
æé
user_info, user_role ãã¼ãã«ã«ç»é²ããå¦çãå®è£ ãã
-
src/main/java/ksbysample/eipapp/dirchecker/service/userinfo ã®ä¸ã® UserInfoService.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
ksbysample-webapp-lending ãã以ä¸ã®ãã¡ã¤ã«ãã³ãã¼ãã¾ãã
ã³ãã¼ãã¦ãã src/main/resources ã®ä¸ã® applicationContext.xml ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
DBãã¹ãç¨ã®ã©ã¤ãã©ãªãå©ç¨ãããã®ã§ãksbysample-webapp-lending ãã src/test/java/ksbysample/common/test/rule/db ããã©ã«ãæ¯ã³ãã¼ãã¾ãã
ã³ãã¼ãã¦ãã src/test/java/ksbysample/common/test/rule/db ã®ä¸ã® TestDataResource.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
ksbysample/eipapp/dirchecker ã®ä¸ã® Application.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
DbUnit ãå©ç¨ãããã®ã§ build.gradle ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
Gradle projects View ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ã㦠build.gradle ãåæ ãã¾ãã
src/test/resources ã®ä¸ã« testdata/base ãã£ã¬ã¯ããªãä½æãã¾ãã
src/test/resources/testdata/base ã®ä¸ã« user_info.csv, user_role.csv, lending_app.csv, lending_book.csv, table-ordering.txt ãä½æãã¾ããä½æå¾ããªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo ã®ä¸ã« testdata/001 㨠assertdata/001 ãã£ã¬ã¯ããªãä½æãã¾ãã
src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo/testdata/001 ã®ä¸ã« user_info.csv, user_role.csv, table-ordering.txt ãä½æãã¾ããä½æå¾ããªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
â»å®éã«ã¯ src/test/resources/testdata/base ã®ãã¼ã¿ã§ã¯ãªã¢ãããã®ã§ src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo/testdata/001 ã®ãã¼ã¿ã¯ä¸è¦ãªã®ã§ããããã¹ãç¨ã©ã¤ãã©ãªã®ä½¿ãæ¹ãæãåºãããã«ç¨æãã¦ãã¾ãã
src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo/assertdata/001 ã®ä¸ã« user_info.csv, user_role.csv, table-ordering.txt ãä½æãã¾ããä½æå¾ããªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
UserInfoService#loadUserInfoFromExcel ã¡ã½ããã®ãã¹ããä½æãã¾ããsrc/test/java/ksbysample/eipapp/dirchecker/service/userinfo ã®ä¸ã® UserInfoServiceTest.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
UserInfoServiceTest#loadUserInfoFromExcel ãã¹ãã¡ã½ãããå®è¡ãã¾ãããã
transactionManager
Bean ã® NoSuchBeanDefinitionException ã§ã¨ã©ã¼ã«ãªãã¾ãããé常èªåã§çæãããã¯ããªã®ã§ãããããï¼
ãªã transactionManager Bean ãèªåçæãããªãã£ãã®ãï¼
Spring Boot ã® GitHub ( https://github.com/spring-projects/spring-boot ) ã® spring-boot-autoconfigure ã®ä¸ã«èªåçæãã¦ããã½ã¼ã¹ãããã¯ããªã®ã§ç¢ºèªãã¦ã¿ã¾ãã
spring-boot/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java ã TransactionManager ã® AutoConfiguration ã®ã½ã¼ã¹ã®ããã§ããããããè¦ã㨠@ConditionalOnSingleCandidate(PlatformTransactionManager.class)
ã¨ããè¨è¿°ãããã¾ãããPlatformTransactionManager ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å®è£
ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãæ¢ã«çæããã¦ããå ´åã«ã¯èªåçæãããªãããã§ãã
TransactionManager ã¨è¨ãã°ãä»åã®å®è£ ã§ã¯ src/main/java/ksbysample/eipapp/dirchecker/eip/config ã®ä¸ã® TransactionConfig.java 㧠pseudoTransactionManager Bean ãçæãã¦ãã¾ããã
@Configuration public class TransactionConfig { @Bean public PseudoTransactionManager pseudoTransactionManager() { return new PseudoTransactionManager(); } }
PseudoTransactionManager ã¯ã©ã¹ã確èªãã㨠PlatformTransactionManager ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å®è£ ã¯ã©ã¹ã§ããã
ãã£ã¦çµè«ã¯ãã¢ããªã±ã¼ã·ã§ã³å 㧠PlatformTransactionManager ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å®è£ ã¯ã©ã¹ã§ãã PseudoTransactionManager ã¯ã©ã¹ã® Bean ãçæãã¦ãããããSpring Boot ã® AutoConfiguration 㧠transactionManager Bean ãèªåçæãããªãã£ããã¨ããä»çµã¿ã§ããã
transactionManager Bean ãçæãã
transactionManager Bean ãã¢ããªã±ã¼ã·ã§ã³å ã§çæããããã«ãã¾ãã
- IntelliJ IDEA 㧠Shift ãã¼ãï¼åæ¼ãã¦æ¤ç´¢ã¦ã£ã³ãã¦ã表示ããå¾ “TransactionManager” ã§æ¤ç´¢ããã¨ãDataSourceTransactionManager ã¨ããã¯ã©ã¹ãè¦ã¤ããã¾ãããé常èªåçæããã TransactionManager ã¯ãã®ã¯ã©ã¹ã§ãã®ã§ããã®ã¯ã©ã¹ã§ transactionManager Bean ãçæãã¾ãã
- src/main/java/ksbysample/eipapp/dirchecker/eip/config ã®ä¸ã® TransactionConfig.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
å度 UserInfoServiceTest#loadUserInfoFromExcel ãã¹ãã¡ã½ãããå®è¡ãã
UserInfoServiceTest#loadUserInfoFromExcel ãã¹ãã¡ã½ãããå®è¡ããã¨ä»åº¦ã¯æåãã¾ããã
FileProcessor#process ãã UserInfoService#loadUserInfoFromExcel ãå¼ã³åºãããå®è£ ãã
- src/main/java/ksbysample/eipapp/dirchecker/eip/endpoint ã®ä¸ã® FileProcessor.java ã ãªã³ã¯å ã®å 容 ã«å¤æ´ãã¾ãã
åä½ç¢ºèª
確èªåã® user_info, user_role ã®ãã¼ã¿ã¯ä»¥ä¸ã®ç¶æ ã§ãã
in ãã£ã¬ã¯ããªãerror ãã£ã¬ã¯ããªã¯ç©ºã«ãã¾ãã
clean ã¿ã¹ã¯å®è¡ â Rebuild Project å®è¡ãããå¾ã« bootRun ã¿ã¹ã¯ãå®è¡ã㦠Tomcat ãèµ·åãã¾ãã
src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo ã®ä¸ã® TestData01.xlsx ã in ãã£ã¬ã¯ããªã«ã³ãã¼ããã¨ãããã«ãã¡ã¤ã«ããªããªãã¾ãããerror ãã£ã¬ã¯ããªã«ã¯ç§»åãã¦ãã¾ããã
âââ
user_info, user_role ã«ã¯ä»¥ä¸ã®ããã«ãã¼ã¿ãç»é²ããã¦ãã¾ããã
ç»é²ããããã¼ã¿ã¯åé¤ããCtrl+F2 ãæ¼ã㦠Tomcat ãåæ¢ãã¾ãã
次ã«ä¾å¤çºçæã« error ãã£ã¬ã¯ããªã«ç§»åããã試ãã¾ããUserInfoService#loadUserInfoFromExcel å ã§ä»¥ä¸ã®ããã« RuntimeException ã throw ãããããã«å¤æ´ãã¾ãã
bootRun ã¿ã¹ã¯ãå®è¡ã㦠Tomcat ãèµ·åãã¾ãã
TestData01.xlsx ã in ãã£ã¬ã¯ããªã«ã³ãã¼ããã¨ãããã« error ãã£ã¬ã¯ããªã«ãã¡ã¤ã«ã移åãã¾ããã
âââ
user_info, user_role ãã¼ãã«ã«ããã¼ã¿ã¯ç»é²ããã¦ãã¾ããã§ããã
ç¡äºæ£å¸¸ã«åä½ãã¦ããããã§ãã
ãã ããã®ã¾ã¾ Tomcat ãèµ·åãã¦ããç¶æ 㧠error ãã£ã¬ã¯ããªã® TestData01.xlsx ãåé¤ãã¦ããå度 in ãã£ã¬ã¯ããªã« TestData01.xlsx ãã³ãã¼ãã¦ããã¡ã¤ã«ã¯åé¤ã移åããããªããã§ãããããã
AcceptOnceFileListFilter ãå ¥ãã¦ããªãã®ã«åä¸ãã¡ã¤ã«ãå¦çãããªããªãä»çµã¿ãåãããªãã®ã§ã次å調æ»ãã¦ã¿ã¾ãã
Ctrl+F2 ãæ¼ã㦠Tomcat ãåæ¢ããUserInfoService#loadUserInfoFromExcel ãå ã«æ»ãã¾ãã
ã½ã¼ã¹ã³ã¼ã
UserInfoService.java
package ksbysample.eipapp.dirchecker.service.userinfo; import ksbysample.eipapp.dirchecker.dao.UserInfoDao; import ksbysample.eipapp.dirchecker.dao.UserRoleDao; import ksbysample.eipapp.dirchecker.entity.UserInfo; import ksbysample.eipapp.dirchecker.entity.UserRole; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.jxls.reader.ReaderBuilder; import org.jxls.reader.XLSReadStatus; import org.jxls.reader.XLSReader; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.xml.sax.SAXException; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class UserInfoService { private static final String CLASSPATH_USERINFO_EXCEL_CFG_XML = "ksbysample/eipapp/dirchecker/service/userinfo/userinfo-excel-cfg.xml"; @Autowired private UserInfoDao userInfoDao; @Autowired private UserRoleDao userRoleDao; public void loadUserInfoFromExcel(File excelFile) throws InvalidFormatException, SAXException, IOException { // Excel ãã¡ã¤ã«ãããã¼ã¿ãèªã¿è¾¼ã List<UserInfoExcelRow> userInfoExcelRowList = loadFromExcelToList(excelFile); // user_info, user_role ãã¼ãã«ã«ç»é²ãã userInfoExcelRowList.forEach(userInfoExcelRow -> { UserInfo userInfo = makeUserInfo(userInfoExcelRow); userInfoDao.insert(userInfo); userInfoExcelRow.getRoleListFromRoles().forEach(role -> { UserRole userRole = makeUserRole(userInfo.getUserId(), role); userRoleDao.insert(userRole); }); }); } public List<UserInfoExcelRow> loadFromExcelToList(File excelFile) throws IOException, SAXException, InvalidFormatException { Resource rsExcelCfgXml = new ClassPathResource(CLASSPATH_USERINFO_EXCEL_CFG_XML); Resource rsUserInfoExcel = new FileSystemResource(excelFile.getAbsolutePath()); XLSReader reader = ReaderBuilder.buildFromXML(rsExcelCfgXml.getFile()); List<UserInfoExcelRow> userInfoExcelRowList = new ArrayList<>(); Map<String, Object> beans = new HashMap<>(); beans.put("userInfoExcelRow", new UserInfoExcelRow()); beans.put("userInfoExcelRowList", userInfoExcelRowList); try (InputStream isUserInfoExcel = new BufferedInputStream(rsUserInfoExcel.getInputStream())) { XLSReadStatus status = reader.read(isUserInfoExcel, beans); } return userInfoExcelRowList; } private UserInfo makeUserInfo(UserInfoExcelRow userInfoExcelRow) { UserInfo userInfo = new UserInfo(); BeanUtils.copyProperties(userInfoExcelRow, userInfo); userInfo.setPassword(new BCryptPasswordEncoder().encode(userInfoExcelRow.getPassword())); userInfo.setEnabled((short) 1); userInfo.setCntBadcredentials((short) 0); userInfo.setExpiredAccount(LocalDateTime.now().plusMonths(3)); userInfo.setExpiredPassword(LocalDateTime.now().plusMonths(1)); return userInfo; } private UserRole makeUserRole(Long userId, String role) { UserRole userRole = new UserRole(); userRole.setUserId(userId); userRole.setRole(role); return userRole; } }
@Autowired private UserInfoDao userInfoDao;
ã追å ãã¾ãã@Autowired private UserRoleDao userRoleDao;
ã追å ãã¾ãã- makeUserInfo ã¡ã½ãããmakeUserRole ã¡ã½ããã追å ãã¾ãã
- loadUserInfoFromExcel ã¡ã½ããã追å ãã¾ãã
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" rollback-for="Exception"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="pointcutService" expression="execution(* ksbysample.eipapp.dirchecker..*Service.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcutService"/> </aop:config> </beans>
<aop:pointcut id="pointcutService" expression="..."/>
ã® expression ã®è¨è¿°ãexecution(* ksbysample.webapp.lending..*Service.*(..))
âexecution(* ksbysample.eipapp.dirchecker..*Service.*(..))
ã¸å¤æ´ãã¾ãã
TestDataResource.java
@Component public class TestDataResource extends TestWatcher { private static final String BASETESTDATA_ROOT_DIR = "src/test/resources/"; private static final String TESTDATA_ROOT_DIR = "src/test/resources/ksbysample/webapp/lending/"; private static final String BASETESTDATA_DIR = BASETESTDATA_ROOT_DIR + "testdata/base"; private static final String BACKUP_FILE_NAME = "ksbylending_backup"; ..........
- TESTDATA_ROOT_DIR ã®æååã
src/test/resources/ksbysample/webapp/lending/
âsrc/test/resources/ksbysample/eipapp/dirchecker/
ã¸å¤æ´ãã¾ãã
Application.java
package ksbysample.eipapp.dirchecker; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.context.annotation.ImportResource; @ImportResource("classpath:applicationContext.xml") @SpringBootApplication(exclude = {JpaRepositoriesAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) @ComponentScan("ksbysample") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
@ImportResource("classpath:applicationContext.xml")
ã追å ãã¾ãã@ComponentScan("ksbysample")
ã追å ãã¾ãã
build.gradle
dependencies { def jdbcDriver = "org.postgresql:postgresql:9.4.1209" // dependency-management-plugin ã«ãããã¼ã¸ã§ã³çªå·ãèªåã§è¨å®ããããã® // Appendix A. Dependency versions ( http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions ) åç § compile('org.springframework.boot:spring-boot-starter-integration') compile('org.springframework.integration:spring-integration-file') compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-data-jpa") testCompile("org.springframework.boot:spring-boot-starter-test") testCompile("org.spockframework:spock-core") testCompile("org.spockframework:spock-spring") // dependency-management-plugin ã«ãããã¼ã¸ã§ã³çªå·ãèªåã§è¨å®ãããªããã®ããããã¯ææ°ãã¼ã¸ã§ã³ãæå®ããããã® runtime("${jdbcDriver}") compile("org.seasar.doma:doma:2.12.1") compile("org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16") compile("org.projectlombok:lombok:1.16.10") compile("org.apache.commons:commons-lang3:3.4") compile("org.jxls:jxls-reader:2.0.2") testCompile("org.assertj:assertj-core:3.5.2") testCompile("org.dbunit:dbunit:2.5.3") // for Doma-Gen domaGenRuntime("org.seasar.doma:doma-gen:2.12.1") domaGenRuntime("${jdbcDriver}") }
testCompile("org.dbunit:dbunit:2.5.3")
ã追å ãã¾ãã
testdata/base/user_info.csv, user_role.csv, lending_app.csv, lending_book.csv, table-ordering.txt
â user_info.csv
user_id,username,password,mail_address,enabled,cnt_badcredentials,expired_account,expired_password
â user_role.csv
role_id,user_id,role
â lending_app.csv
lending_app_id,status,lending_user_id,approval_user_id,version
â lending_book.csv
lending_book_id,lending_app_id,isbn,book_name,lending_state,lending_app_flg,lending_app_reason,approval_result,approval_reason,version
â table-ordering.txt
user_info user_role lending_app lending_book
testdata/001/user_info.csv, user_role.csv, table-ordering.txt
â user_info.csv
user_id,username,password,mail_address,enabled,cnt_badcredentials,expired_account,expired_password
â user_role.csv
role_id,user_id,role
â table-ordering.txt
user_info user_role
- user_info, user_role ã©ã¡ãã«ããã¼ã¿ã¯è¨è¿°ãã¾ããããã¼ãã«ãã¯ãªã¢ããã®ãç®çã§ãã
assertdata/001/user_info.csv, user_role.csv, table-ordering.txt
â user_info.csv
user_id,username,password,mail_address,enabled,cnt_badcredentials,expired_account,expired_password ,yota takahashi,,[email protected],1,0,, ,aoi inoue,,[email protected],1,0,,
- æ¤è¨¼ã«ä½¿ç¨ãã username, mail_address, enabled, cnt_badcredentials ã®ã¿è¨è¿°ãã¾ãã
â user_role.csv
role_id,user_id,role ,,ROLE_USER ,,ROLE_ADMIN ,,ROLE_USER
- æ¤è¨¼ã«ä½¿ç¨ãã role ã®ã¿è¨è¿°ãã¾ãã
â table-ordering.txt
user_info user_role
UserInfoServiceTest.java
package ksbysample.eipapp.dirchecker.service.userinfo; import ksbysample.common.test.rule.db.*; import ksbysample.eipapp.dirchecker.Application; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.csv.CsvDataSet; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.sql.DataSource; import java.io.File; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) public class UserInfoServiceTest { private static final String CLASSPATH_EXCEL_FOR_TEST = "ksbysample/eipapp/dirchecker/service/userinfo/Book1.xlsx"; @Rule @Autowired public TestDataResource testDataResource; @Autowired private DataSource dataSource; @Autowired private UserInfoService userInfoService; @Test @NoUseTestDataResource public void loadFromExcelToList() throws Exception { Resource resource = new ClassPathResource(CLASSPATH_EXCEL_FOR_TEST); List<UserInfoExcelRow> userInfoExcelRowList = userInfoService.loadFromExcelToList(resource.getFile()); assertThat(userInfoExcelRowList).hasSize(2); assertThat(userInfoExcelRowList).extracting("username", "password", "mailAddress", "roles") .containsOnly(tuple("yota takahashi", "12345678", "[email protected]", "ROLE_USER") , tuple("aoi inoue", "abcdefgh", "[email protected]", "ROLE_ADMIN,ROLE_USER")); } @Test @TestData("service/userinfo/testdata/001") public void loadUserInfoFromExcel() throws Exception { Resource resource = new ClassPathResource(CLASSPATH_EXCEL_FOR_TEST); userInfoService.loadUserInfoFromExcel(resource.getFile()); IDataSet dataSet = new CsvDataSet(new File("src/test/resources/ksbysample/eipapp/dirchecker/service/userinfo/assertdata/001")); TableDataAssert tableDataAssert = new TableDataAssert(dataSet, dataSource); tableDataAssert.assertEqualsByQuery( "select username, mail_address, enabled, cnt_badcredentials from user_info order by user_id" , "user_info" , new String[]{"username", "mail_address", "enabled", "cnt_badcredentials"} , AssertOptions.INCLUDE_COLUMN); tableDataAssert.assertEqualsByQuery("select role from user_role order by user_id, role_id" , "user_role" , new String[]{"role"} , AssertOptions.INCLUDE_COLUMN); } }
@Rule @Autowired public TestDataResource testDataResource;
ã追å ãã¾ãã@Autowired private DataSource dataSource;
ã追å ãã¾ãã- loadFromExcelToList ãã¹ãã¡ã½ããã«
@NoUseTestDataResource
ã¢ããã¼ã·ã§ã³ãä»å ãã¾ãã - loadUserInfoFromExcel ãã¹ãã¡ã½ããã追å ãã¾ãã
TransactionConfig.java
package ksbysample.eipapp.dirchecker.eip.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.transaction.PseudoTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import javax.sql.DataSource; @Configuration public class TransactionConfig { @Autowired private DataSource dataSource; @Bean public PseudoTransactionManager pseudoTransactionManager() { return new PseudoTransactionManager(); } @Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(this.dataSource); } }
@Autowired private DataSource dataSource;
ã追å ãã¾ãã- transactionManager ã¡ã½ããã追å ãã¾ãã
FileProcessor.java
package ksbysample.eipapp.dirchecker.eip.endpoint; import ksbysample.eipapp.dirchecker.service.userinfo.UserInfoService; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.Message; import org.xml.sax.SAXException; import java.io.File; import java.io.IOException; @MessageEndpoint public class FileProcessor { @Autowired private UserInfoService userInfoService; @ServiceActivator(inputChannel = "excelToDbChannel") public void process(Message<File> message) throws InvalidFormatException, SAXException, IOException { File file = message.getPayload(); userInfoService.loadUserInfoFromExcel(file); } }
@Autowired private UserInfoService userInfoService;
ã追å ãã¾ãã- process ã¡ã½ããå
ã§
userInfoService.loadUserInfoFromExcel(file);
ãå¼ã³åºãããã«å¤æ´ãã¾ãã
å±¥æ´
2016/09/07
åççºè¡ã