Spring Boot 1.2.x ã® Web ã¢ããªã 1.3.x ã¸ãã¼ã¸ã§ã³ã¢ãããã ( ãã®ï¼ )( JRebel 㨠devtools ãã©ã¡ããå ¥ããæã®åä½ã確èªãã )
æ¦è¦
Spring Boot 1.2.x ã® Web ã¢ããªã 1.3.x ã¸ãã¼ã¸ã§ã³ã¢ãããã ( ãã®ï¼ )( 1.2 â 1.3 ã§å®è£ æ¹æ³ãå¤æ´ãããç®æãä¿®æ£ãã ) ã®ç¶ãã§ãã
- ä»åã®æé ã§ç¢ºèªã§ããã®ã¯ä»¥ä¸ã®å
容ã§ãã
- JRebel 㨠devtools ãã©ã¡ããå ¥ããæã®åä½ã確èªãã
åç §ãããµã¤ãã»æ¸ç±
-
20. Developer tools
http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html -
DevTools in Spring Boot 1.3
https://spring.io/blog/2015/06/17/devtools-in-spring-boot-1-3 spring-boot-devtoolsã§éçºå¹çä¸ãããããçãªã (Spring Boot 1.3)
http://qiita.com/IsaoTakahashi/items/f99d5f761d1d4190860dDevToolsPropertyDefaultsPostProcessor.java
https://github.com/spring-projects/spring-boot/blob/v1.3.5.RELEASE/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java
ç®æ¬¡
- build.gradle ãå¤æ´ãã
- application-develop.properties, application-unittest.properties, application-product.properties ãä¿®æ£ãã
- JRebel 㨠devtools ãä½µç¨ãã¦ããç¶æ ã§ãããããæ£å¸¸ã«åä½ãããã¨ã確èªãã
- spring.thymeleaf.cache ã IDE ã§èµ·åããæã«ã¯ false ã«ãjava -jar ã§èµ·åããæã«ã¯ true ã«ãªããã¨ã確èªãã
- devtools ãå¤ã㦠java -jar ã§èµ·åãã㨠spring.thymeleaf.cache ã true ã«ãªãã確èªãã
- 次åã¯ããã
æé
build.gradle ãå¤æ´ãã
build.gradle ã以ä¸ã®ããã«å¤æ´ãã¾ãã
dependencies { def jdbcDriver = "org.postgresql:postgresql:9.4.1208" // 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-web") compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4") compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-velocity") compile("org.springframework.boot:spring-boot-starter-mail") compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-redis") compile("org.springframework.boot:spring-boot-starter-amqp") compile("org.springframework.boot:spring-boot-devtools") compile("org.springframework.session:spring-session") compile("org.codehaus.janino:janino") compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") testCompile("org.springframework.boot:spring-boot-starter-test") testCompile("org.springframework.security:spring-security-test") testCompile("org.yaml:snakeyaml") testCompile("org.spockframework:spock-core") { exclude module: "groovy-all" } testCompile("org.spockframework:spock-spring") { exclude module: "groovy-all" } // dependency-management-plugin ã«ãããã¼ã¸ã§ã³çªå·ãèªåã§è¨å®ãããªããã®ããããã¯ææ°ãã¼ã¸ã§ã³ãæå®ããããã® runtime("${jdbcDriver}") compile("org.seasar.doma:doma:2.8.0") compile("org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16") compile("org.apache.commons:commons-lang3:3.4") compile("org.projectlombok:lombok:1.16.8") compile("com.google.guava:guava:19.0") compile("org.simpleframework:simple-xml:2.7.1") compile("com.univocity:univocity-parsers:2.1.1") compile("org.thymeleaf.extras:thymeleaf-extras-java8time:2.1.0.RELEASE") testCompile("org.dbunit:dbunit:2.5.1") testCompile("com.icegreen:greenmail:1.5.0") testCompile("org.assertj:assertj-core:3.4.1") testCompile("com.jayway.jsonpath:json-path:2.2.0") testCompile("org.jmockit:jmockit:1.23") // for Doma-Gen domaGenRuntime("org.seasar.doma:doma-gen:2.8.0") domaGenRuntime("${jdbcDriver}") }
compile("org.springframework.boot:spring-boot-devtools")
ã追å ãã¾ãã
å¤æ´å¾ãGradle projects View ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ãã¦æ´æ°ãã¾ãã
application-develop.properties, application-unittest.properties, application-product.properties ãä¿®æ£ãã
cache ã® ON/OFF ãè¨å®ãã¦ããé¨åãã³ã¡ã³ãã¢ã¦ããã¾ãã
â application-develop.properties
spring.datasource.url=jdbc:log4jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy spring.mail.host=localhost spring.mail.port=25 spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 #spring.messages.cache-seconds=0 #spring.thymeleaf.cache=false #spring.velocity.cache=false
- 以ä¸ã®ï¼é
ç®ãã³ã¡ã³ãã¢ã¦ããã¾ãã
- spring.messages.cache-seconds=0
- spring.thymeleaf.cache=false
- spring.velocity.cache=false
â application-unittest.properties
spring.datasource.url=jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=org.postgresql.Driver spring.mail.host=localhost spring.mail.port=25 spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 #spring.thymeleaf.cache=true
- 以ä¸ã®ï¼é
ç®ãã³ã¡ã³ãã¢ã¦ããã¾ãã
- spring.thymeleaf.cache=true
â application-product.properties
server.tomcat.basedir=C:/webapps/ksbysample-webapp-lending logging.file=${server.tomcat.basedir}/logs/ksbysample-webapp-lending.log spring.datasource.url=jdbc:postgresql://localhost/ksbylending spring.datasource.username=ksbylending_user spring.datasource.password=xxxxxxxx spring.datasource.driverClassName=org.postgresql.Driver spring.mail.host=localhost spring.mail.port=25 spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.redis.sentinel.master=mymaster spring.redis.sentinel.nodes=localhost:6381,localhost:6382,localhost:6383 #spring.thymeleaf.cache=true
- 以ä¸ã®ï¼é
ç®ãã³ã¡ã³ãã¢ã¦ããã¾ãã
- spring.thymeleaf.cache=true
JRebel 㨠devtools ãä½µç¨ãã¦ããç¶æ ã§ãããããæ£å¸¸ã«åä½ãããã¨ã確èªãã
ã¾ã㯠devtools 㧠Automatic Restart ãåä½ãããã¨ã確èªãã¾ãã
æåã« IntelliJ IDEA ã®ç»é¢å³ä¸ã®ãSelect Run/Debug Configurationãã§ãApplicationããé¸æããå¾ããRunããã¿ã³ãã¯ãªãã¯ã㦠Tomcat ãèµ·åãã¾ã ( JRebel ã使ç¨ããã« Tomcat ãèµ·åãã¾ã )ã
src/main/java/ksbysample/webapp/lending ã®ä¸ã«ä»¥ä¸ã® SampleController.java ãä½æãã¾ãã
package ksbysample.webapp.lending; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/sample") public class SampleController { @RequestMapping @ResponseBody public String index() { return "sample"; } }
Ctrl+F9 ãæ¼ã㦠Compile ãã¾ããCompile ãå®äºãã㨠devtools ã® Automatic Restart ãå®è¡ããã¾ãããé常起åæ㯠18ç§ã»ã©ãããã¾ããããAutomatic Restart ã 㨠7ç§ç¨åº¦ã§åèµ·åãå®äºãã¾ãã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ãã㨠"sample" ã®æåã表示ããããã¨ã確èªã§ãã¾ããJRebel ã使ç¨ãã¦ããªãã®ã«æ°è¦ã« ä½æãã Controller ã¯ã©ã¹ãåæ ãããã¨ã¯ä¾¿å©ã§ããã
Tomcat ãåæ¢ãã¾ãã
次㫠JRebel ãåä½ãããã¨ã確èªãã¾ãã
IntelliJ IDEA ã®ç»é¢å³ä¸ã®ãSelect Run/Debug Configurationãã§ãApplicationããé¸æããå¾ããRun with JRebelããã¿ã³ãã¯ãªãã¯ã㦠Tomcat ãèµ·åãã¾ãã
src/main/java/ksbysample/webapp/lending ã®ä¸ã® SampleController.java ã以ä¸ã®ããã«å¤æ´ãã¾ãã
package ksbysample.webapp.lending; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/sample") public class SampleController { @RequestMapping @ResponseBody public String index() { return "test"; } }
return "sample";
âreturn "test";
ã¸å¤æ´ãã¾ãã
Ctrl+F9 ãæ¼ã㦠Compile ãã¾ããCompile ãå®äºãã㨠JRebel: Reloading class 'ksbysample.webapp.lending.SampleController'.
ã®ã¡ãã»ã¼ã¸ãåºåãã㦠JRebel ã class ããªãã¼ããã¾ãããã¾ã devtools ã® Automatic Restart ãå®è¡ããã¦ããæã®ãããªãã°ã¯åºåããã¾ããã§ãããJRebel ã¯å¤æ´ã®ãã£ãã¯ã©ã¹ã ãããªãã¼ããã¦ãããããªã®ã§ããªãã¼ãã«ãããæéã¯ãã¡ãã®æ¹ãéãã§ããã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ãã㨠"test" ã®æåã表示ããããã¨ã確èªã§ãã¾ãã
devtools ãå ¥ã£ã¦ãã¦ã JRebel ã®åä½ã«ã¯å½±é¿ãªãããã§ãã
spring.thymeleaf.cache ã IDE ã§èµ·åããæã«ã¯ false ã«ãjava -jar ã§èµ·åããæã«ã¯ true ã«ãªããã¨ã確èªãã
20. Developer tools ãè¦ã㨠java -jar ã§èµ·åããã devtools ã¯èªåçã« disable ã«ãªããããã®ã§ãspring.thymeleaf.cache ã true ã«ãªãã®ã確èªãããã¨æãã¾ãã
spring.thymeleaf.cache ã®å¤ã確èªã§ãããããsrc/main/java/ksbysample/webapp/lending ã®ä¸ã® SampleController.java ã以ä¸ã®ããã«å¤æ´ãã¾ãã
package ksbysample.webapp.lending; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/sample") public class SampleController { @Value("${spring.thymeleaf.cache:}") private String springThymeleafCache; @RequestMapping @ResponseBody public String index() { return "spring.thymeleaf.cache = " + springThymeleafCache; } }
ã¾ã㯠IntelliJ IDEA ãã Tomcat ãèµ·åããå ´åã«ã¯ false ã¨è¡¨ç¤ºããããã¨ã確èªãã¾ãã
IntelliJ IDEA ã®ç»é¢å³ä¸ã®ãSelect Run/Debug Configurationãã§ãApplicationããé¸æããå¾ããRunããã¿ã³ãã¯ãªãã¯ã㦠Tomcat ãèµ·åãã¾ã ( JRebel ã使ç¨ããã« Tomcat ãèµ·åãã¾ã )ã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ãã㨠spring.thymeleaf.cache = false
ã¨è¡¨ç¤ºããããã¨ã確èªã§ãã¾ãã
Tomcat ãåæ¢ãã¾ãã
JRebel 㧠Tomcat ãèµ·åããæã false ã¨è¡¨ç¤ºãããã®ã確èªãã¦ã¿ã¾ãã
IntelliJ IDEA ã®ç»é¢å³ä¸ã®ãSelect Run/Debug Configurationãã§ãApplicationããé¸æããå¾ããRun with JRebelããã¿ã³ãã¯ãªãã¯ã㦠Tomcat ãèµ·åãã¾ãã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ããã¨åãããã« spring.thymeleaf.cache = false
ã¨è¡¨ç¤ºããããã¨ã確èªã§ãã¾ãã
Tomcat ãåæ¢ãã¾ãã
ä»åº¦ã¯ jar ãã¡ã¤ã«ãä½æã㦠java -jar ã§èµ·åããæã« true ã¨è¡¨ç¤ºããããã¨ã確èªãã¾ãã
Gradle projects View ãã clean ã¿ã¹ã¯ã®å®è¡âãRebuild Projectãã¡ãã¥ã¼ã®å®è¡âbuild ã¿ã¹ã¯ã®å®è¡ãè¡ããksbysample-webapp-lending-1.1.0-RELEASE.jar ãä½æãã¾ãã
ksbysample-webapp-lending-1.1.0-RELEASE.jar ã C:\webapps\ksbysample-webapp-lending\lib ã®ä¸ã¸ã³ãã¼ãã¾ãã
C:\webapps\ksbysample-webapp-lending\bat ã®ä¸ã® webapp_startup.bat ã以ä¸ã®ããã«å¤æ´ãã¾ãã
@echo on setlocal set JAVA_HOME=C:\Java\jdk1.8.0_92 set PATH=%JAVA_HOME%\bin;%PATH% set WEBAPP_HOME=C:\webapps\ksbysample-webapp-lending set WEBAPP_JAR=ksbysample-webapp-lending-1.1.0-RELEASE.jar cd /d %WEBAPP_HOME% java -server ^ -Xms1024m -Xmx1024m ^ -XX:MaxMetaspaceSize=384m ^ -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled ^ -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 ^ -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark ^ -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps ^ -Xloggc:%WEBAPP_HOME%/logs/gc.log ^ -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=10M ^ -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%WEBAPP_HOME%/logs/`date`.hprof ^ -XX:ErrorFile=%WEBAPP_HOME%/logs/hs_err_pid_%p.log ^ -Dsun.net.inetaddr.ttl=100 ^ -Dcom.sun.management.jmxremote ^ -Dcom.sun.management.jmxremote.port=7900 ^ -Dcom.sun.management.jmxremote.ssl=false ^ -Dcom.sun.management.jmxremote.authenticate=false ^ -Dspring.profiles.active=product ^ -jar lib\%WEBAPP_JAR%
set JAVA_HOME=C:\Java\jdk1.8.0_77
âset JAVA_HOME=C:\Java\jdk1.8.0_92
ã¸å¤æ´ãã¾ããset WEBAPP_JAR=ksbysample-webapp-lending-1.0.0-RELEASE.jar
âset WEBAPP_JAR=ksbysample-webapp-lending-1.1.0-RELEASE.jar
ã¸å¤æ´ãã¾ãã
webapp_startup.bat ãå®è¡ãã¾ãã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ãã㨠spring.thymeleaf.cache = false
ã¨è¡¨ç¤ºããã¾ãããjavar -jar ã§èµ·åããã®ã« true ã«ãªãã¾ãããããã
webapp_startup.bat å®è¡æã«éããã³ãã³ãããã³ãããéãã¾ãã
devtools ãå¤ã㦠java -jar ã§èµ·åãã㨠spring.thymeleaf.cache ã true ã«ãªãã確èªãã
devtools ãå¤ããã spring.thymeleaf.cache ãã©ã表示ãããã®ã確èªãã¦ã¿ã¾ãã
build.gradle ã® compile("org.springframework.boot:spring-boot-devtools")
ã®è¡ãã³ã¡ã³ãã¢ã¦ããã¾ããå¤æ´å¾ãGradle projects View ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ãã¦æ´æ°ãã¾ãã
Gradle projects View ãã clean ã¿ã¹ã¯ã®å®è¡âãRebuild Projectãã¡ãã¥ã¼ã®å®è¡âbuild ã¿ã¹ã¯ã®å®è¡ãè¡ããksbysample-webapp-lending-1.1.0-RELEASE.jar ãä½æãç´ãã¾ãã
ksbysample-webapp-lending-1.1.0-RELEASE.jar ã C:\webapps\ksbysample-webapp-lending\lib ã®ä¸ã¸ã³ãã¼ããå¾ãwebapp_startup.bat ãå®è¡ãã¾ãã
http://localhost:8080/sample/ ã«ã¢ã¯ã»ã¹ããã¨ä»åº¦ã¯ spring.thymeleaf.cache =
ã¨è¡¨ç¤ºããã¾ãããAppendix A. Common application properties ãè¦ã㨠spring.thymeleaf.cache=true # Enable template caching.
ã¨è¨è¼ããã¦ãã¾ãã®ã§ãæªè¨å®æ㯠true ã«ãªã£ã¦ããã¨èãã¦ããã§ãããã
webapp_startup.bat å®è¡æã«éããã³ãã³ãããã³ãããéãã¾ãã
build.gradle ã® compile("org.springframework.boot:spring-boot-devtools")
ã®ã³ã¡ã³ãã¢ã¦ããå
ã«æ»ãã¦ãå¤æ´å¾ãGradle projects View ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ãã¦æ´æ°ãã¦ããã¾ãã
次åã¯ããã
java -jar ã§èµ·åãã¦ã spring.thymeleaf.cache = false
ã«ãªãåå ã調æ»ãã¾ããDevToolsPropertyDefaultsPostProcessor.java ãè¦ã㨠remoteUrl
ã null ã 㨠spring.thymeleaf.cache = false
ãè¨å®ããããããªã®ã§ãããremoteUrl
ã¨ã¯ä½ã§ããããï¼
ã½ã¼ã¹ã³ã¼ã
å±¥æ´
2016/05/28
åççºè¡ã