JJUG ナイトセミナ 「Java EE 特集」 - 日本Javaユーザーグループ | Doorkeeper ã§èãã¦ãããã¨ã®ã¡ã¢ã¨ããææ³ã¨ãã§ãã
ãªããã¢ããã¼ã·ã§ã³ããããã¯ããæ£ç¢ºãªå称ã«ãªã£ã¦ãªãã¨ãããããã¾ãããæ¨æ²ãããã©ããªã£ããã§ãã®ã¾ã¾ã«ãã¦ãããããã¯é©å®èªã¿æ¿ãããé¡ãè´ãã¾ããã
CDIãã¯ãããã
ã¹ãã¼ã«ã¼ã¯見習いプログラミング日記ã®id:n_agetsumaæ°ã
Java EE 6ããã¤ãã«EJBã使ããªãDI/AOPä»æ§ãå°å ¥ãSpringã«è¡ã£ã人ããããã帰ã£ã¦ãã¦ãããã®ãï¼ãã¨ããæè©ããå§ã¾ãã
CDIã¨ã¯ãContextï¼ã¹ã³ã¼ããæã£ãï¼DIï¼ä¾åæ§ã®æ³¨å ¥ï¼ã§ããããªã®ã§ãã¾ãDIã®å¾©ç¿ãå ¥ãã
Javaã§Webã¢ããªã±ã¼ã·ã§ã³ä½ãå ´åãã¨ã³ããã¤ã³ãããå¤é¨ã·ã¹ãã ã¸ã®ä¸å±¤ã¬ã¤ã¤ã¼ãåãã®ãä¸è¬çãã§ã¯ãã¬ã¤ã¤ã¼éã¯ã©ãæ¥ç¶ããããnewãã¦ãã¾ãã¨ãã¦ããããã¹ãã«å¿ è¦ãªã¯ã©ã¹ãèã¥ãå¼ã«å¿ è¦ã«ãªã£ã¦ãã¾ããã¦ããããã¹ããã«ãããæéãé£ãã®ã§ã¦ããããã¹ãå°é£ã¨åããçµæã¨ãã¦ãã¹ãã®ãªãã¬ã¬ã·ã¼ã³ã¼ããçã¾ãã¦ãã¾ãã
解決çãã¾ãã¯ã¤ã³ã¿ãã§ã¼ã¹ãåãåºããããããã³ã¼ãã®ã©ããã§newãã¦ã¯ã¢ã³ããªæå³ãç¡ãããã£ã¦ã誰ããå®è£ ã¯ã©ã¹ãæ¢ãã¦èªåã§newãã¦ããããã¨ãªãâ¦â¦ã¨ããã«ãDIã³ã³ããã¨ãããã¼ãºãçã¾ãããã¨ã«ãªã£ãã
ãã£ã¦ããã®ã³ã³ããã®åºæ¬çãªæ©è½ã¯ãã¤ã³ã¿ãã§ã¼ã¹ã«å¯¾å¿ããå®è£ ãåæã«æ¢ãã¦newãããã¨ãããã®ã«ãªããCDIã§ã¯ã@Injectã¢ããã¼ã·ã§ã³ã使ããã¨ãããã«ç¸å½ããããããç¹ã«å¹æãçºæ®ããã®ã¯ã¦ããããã¹ãã®ã¨ãããã®çç±ã¯ãã¦ããããã¹ãã¯ãæ段ã¯ä½ã§ãããããããã¼ã¯ã©ã¹ã«å·®ãæ¿ããããã¨ããã§ããã®ãæä½æ¡ä»¶ãªããã
ãã®ãããã®èª¬æãç´ æ´ãããã®ã¯ãDIã®ã¡ãªããããã¬ã¤ã¤ã¼éã®çµå度ãããã¬ããã§ã¯ãªããã¦ããããã¹ãã®è¦³ç¹ãããã¦ãç¹ã«ããã¨ä¿ºã¯æãã
ã¨ããããã§CDIã«ã¤ãã¦ãJava EE 6ããCDI1.0å°å ¥ãJava EE 7ã§CDI1.1ã¨ãã¦å°è¦æ¨¡ã¢ãããã¼ããæã¯ãJava EE試ããã¨æã£ããé«ä¾¡ãªè£½åè²·ããªãã¨ãã¡ã ã£ããã©ããã¾ã¯ãªã¼ãã³ã½ã¼ã¹ã®ãã®ãå¹¾ã¤ãããã®ã§ãæ°è»½ã«è©¦ããæ代ã«ãªã£ãã
Java EEä»æ§ã§ã®CDIã®ä½ç½®ã¥ããã¬ã¤ã¤ã¼éãç¹ãã®ã主ãªå½¹å²ãã¾ããEJBã使ããªããã¸ãã¹ãã¸ãã¯ã®å®ç¾ãJava EE 5ã¾ã§ã¯EJBã®ã¿DIãã§ããã
å ·ä½çãªã³ã¼ããç¨ããCDIã®ãµã³ãã«èª¬æãJava EE 6ã§ã¯ã@EJBã§ã¯ãªã@Injectã§EJBããã£ã¼ã«ãã¤ã³ã¸ã§ã¯ã·ã§ã³ãå¯è½ã«ã
ã¤ã³ã¸ã§ã¯ã·ã§ã³ãããå´ã®æ¡ä»¶ã«ã¤ãã¦ãã³ã³ããã管çï¼èªåã§newãã¦ãªãï¼ãã¦ããã¤ã³ã¹ã¿ã³ã¹ã§ãããã¨ãå ·ä½çã«ã¯ãServleté¢é£ãEJBãJAX-RSã®ã¨ã³ããã¤ã³ããCDIã§çæãããã¯ã©ã¹ããªã©ãªã©ãã¾ããCDIã«ãã£ã¦çæãããã¤ã³ã¹ã¿ã³ã¹ã«ã¯ãããã«å¥ã®ã¯ã©ã¹ãã¤ã³ã¸ã§ã¯ã·ã§ã³å¯è½ãã¨ã¯ãããéä¸ã§èªåã§newãã¡ãã£ããããããã¡ããªããã¹ãã¼ã«ã¼ã®è¦ãéå»ã¨ãã¦ãStrutsã®ã¢ã¯ã·ã§ã³ã¯ã©ã¹ã«ã¤ã³ã¸ã§ã¯ã·ã§ã³ãããã¨ãããã©ãããªãã£ãããªã©ãããããã
çæãããå´ã®æ¡ä»¶ãå¼æ°ãªãã³ã³ã¹ãã©ã¯ã¿ãããã°ã©ããªã¯ã©ã¹ã§ãæ³¨å ¥å¯è½ã
ã¤ã³ã¿ãã§ã¼ã¹ã®å®è£ ãè¤æ°ããå ´åã¯ï¼ãçãï¼ãããã¤ã«å¤±æãããã©ã®APãµã¼ããããªãæåãããããã
ãã®è§£æ±ºã«ã¯ã@Qualifierãä»ä¸ãããã¢ããã¼ã·ã§ã³ãèªåã§ä½æãä¾ãã°ãRDBMS製åãã¨ã®DAOãä½ãå ´åã@Oracleã¨ãã@PostgreSQLã¨ãèªåã®ã¢ããã¼ã·ã§ã³ã¤ãããããã¯éçãªè§£æ±ºæ¹æ³ã
å®è¡æã«å®è£
ã¬ã¿ã®è§£æ±ºããããå ´åããã¨ãã°ã¦ã¼ã¶ã«ãã£ã¦æ±ºæ¸ã®ã¯ã©ã¹ãåçã«æ±ºå®ãããããªã©ã
ãã¡ãã¯@Producesãã¤ããã
ã¹ã³ã¼ãã«ã¤ãã¦ãåºæ¬çã«ã¯Javaã®webã¢ããªã®éçºè ã§ããã°é¦´æã¿æ·±ããã®ã
@requestscoped ãªã¯ã¨ã¹ãåä»ãå¿çã¾ã§ãã¤ã³ã¸ã§ã¯ã·ã§ã³å¯¾è±¡ã¯ã©ã¹ã«ãããã¤ãã¦ããã¨ããªã¯ã¨ã¹ããã¨ã«ã¤ã³ã¸ã§ã¯ã·ã§ã³ããªãããã¹ãã¼ã«ã¼ã®JBossã§ã®å®é¨ã ã¨ããã£ãã·ã¥ããã¦ããã®ãã©ããããããããªããããããªãã¨ããªãã¸ã§ã¯ãIDãéããã®ã¯è¿ã£ã¦ãããã¨ã®ãã¨ã
@sessionscoped åä¸ã»ãã·ã§ã³ä¸ã¯ãç¶æ ãä¿æãããåä¸ã¤ã³ã¹ã¿ã³ã¹ãã¤ã³ã¸ã§ã¯ã·ã§ã³ãããã
@conversionscoped sessionæªæºã®ä»»æã®é·ã
@dependent ããã©ã«ãããªããã¤ããªãã¨ãã¤ã³ã¸ã§ã¯ã·ã§ã³å ã«ããããã¹ã³ã¼ãã«ãªãããã¨ãã°ãµã¼ãã¬ããã®å ´åãä¸åº¦ã¤ã³ã¹ã¿ã³ã¹ãã§ããã¨ããã¯ãã£ã¨ã³ã³ããã«åå¨ãç¶ããã¯ããªã®ã§ããµã¼ãã¬ããçææã«ä¸åº¦ã ãã¤ã³ã¸ã§ã¯ã·ã§ã³ããããã¨ã«ãªãã
ELå¼ã¨ã®çµã¿åãããJSF 2.x/CDI @namedã«ããELãã¤ã³ãã£ã³ã°ãvalue="#{password.now}" @namedã£ã¦ã¤ãã¦ãã¯ã©ã¹ã«ã ããã¼ãããã¤ã³ããå¯è½ã«ãªãããã®ãããã³ã°ãã¼ã³ãã³ã³ããã¼ã©ã¼ã«ã¤ã³ã¸ã§ã¯ã·ã§ã³ãããã¨ãã£ã使ãæ¹ãããã
ã¤ã³ã¿ã¼ã»ãã¿ã¼ãã¡ã½ããã®éå§çµäºã«å²ãè¾¼ã¿ãæ¥åã¨ã¯ç´æ¥é¢ä¿ãªãã·ã¹ãã å¦çãå®è¡ããããã®ã³ã°ãã»ãã¥ãªãã£é¢é£ããªã©ãªã©ã
ã¤ã³ã¿ã¼ã»ãã¿ã¼ã®ä½ãæ¹ãèªåã¢ããã¼ã·ã§ã³ãä½ããã¤ã³ã¿ã¼ã»ãã¿ã¼ã®å®è£ ãä½ããæå¾ã«@intercoptorbindingã§å®è£ ã¨å¯¾è±¡ãé¢é£ä»ããã¨ãã£ãæé ã
ã¤ã³ã¿ã»ãã¿ã®åªå é ä½ãJava EE 6ã§ã¯beans.xmlãå¿ é ãJava EE 7ã§ã¯@priorityãå°å ¥ãåºæ¬çã«ã¯ãbeans.xmlã«å ã«ãããããã®ããå®è¡ãããã
ã³ã³ãã£ã°ãJava EE 6ã§ã¯ã¤ã³ã¿ã¼ã»ãã¿ã¼ããªãã¦ãbeans.xmlãå¿ é ã7ã§ã¯ãªãã·ã§ã³åâ¦â¦ãªã®ã ãããªãã¦ãåãããã¹ã³ã¼ãæå®ãããªãã¨ã¤ã³ã¿ã¼ã»ãã¿ã¼ãããããªãã®ã§ãæ示çã«@dependentããããªããã°ãªããªãããªã©ãªã©ããã®è¾ºä½æ°ã«ãããããåé¡ãæ½ãã§ãããããã
CDIãJava EE 7ã®ã¢ããªã±ã¼ã·ã§ã³ã§ã©ã使ãããåºæ¬çã«ã¯ä¸å±¤æ§é ã®ã¬ã¤ã¤åé¢ãç¹ã«web層ï¼JSFãjaxrs,websocket,servletï¼ãService(CDI Bean)ãæ°¸ç¶åã®JPA2.xãWeb層ã¯å¤åãç¹ã«æ¿ããã®ã§ãããããåé¢ã§ãããã®ã¯ãªãã¹ãåé¢ãã¦ããããã
EJBã¨ã®ä½¿ãåãã@transactionalã«ãããJava EE 7ããEJBã®å®£è¨çãã©ã³ã¶ã¯ã·ã§ã³ãCDIã ãã§ãã§ããããã«ãªã£ããã¢ãã¯Springã®ããã¨åããRintimeExceptionãã¹ãã¼ãããããã¼ã«ããã¯ã¨ãããããããã©ã³ã¶ã¯ã·ã§ã³ãã³ã³ããã«ã¾ãããããããã«EJBã使ãããã£ãã®ã ãã©ãCDIã®ç»å ´ã§ãã®æ義ãèãã¦ãã¦ããã
ã¨ã¯ãã£ã¦ãã¾ã ã¾ã EJBã«ããã§ããªããã¨ããããéåæå®è¡ãMQé£æºããªã¢ã¼ãå®è¡EJBãã¿ã¤ãæ©è½ï¼cron使ããã¨å¤ãã ãããã©ï¼ãé常ã®webã¢ããªã ã¨EJBãããªããããããã£ã¦è¶£ããããããä¼æ¥ã·ã¹ãã ã ã¨MQã¨ãéåæå®è¡ã¨ãã¯ã¾ã ã¾ã å¿ è¦ã§ãããEJBã¯ãããããªããªããã®ã§ã¯ãªããã¨æãããã
ãªããCDIãåå¼·ããã«ã¯weldã®ããã¥ã¡ã³ãããªã¹ã¹ã¡ããããCDI1.1ããã¾ããããããã®ã¯glassfish 4ãªã®ã§ããã¦ã³ãã¼ããã¦è©¦ãã¾ããããã¨ã®ãã¨ã
åä½ãã¹ãã¯ã©ããã¦ããï¼ãJUnitãªããèªåã§ããã¼ã®å®è£
ã¯ã©ã¹ãnewãã¦ã¤ã£ããã§ãã¾ãã°ããã
arqullian使ãã®ãããã
JSFï¼ã¯ä¿ºãè¯ãç¥ããªãã®ã ãã©ï¼ã«ä¼¼ããããªååã®managedã¢ããã¼ã·ã§ã³ãããããããï¼ãCDIã®ã¢ããã¼ã·ã§ã³ã¤ãã£ãã»ãããããã¨javadocã«ãããã¦ãããmanageã¨ãã¹ã³ã¼ãã¯ãã¹ã¦CDIã®ãã®ã«ç§»è¡ãã¹ããã¨ã®ãã¨ã
ãã¹ã¯ãããã¢ããªã±ã¼ã·ã§ã³ã§CDIããã«ã¯ï¼ãDIãç®çã§ããã°ãguiceã¨ãããã¡ãã£ã¨è»½ããã®ãé¸æããã»ããè¯ããããããªãã
arqullianã®embeddebã¯ãããªãï¼ãremoteã§ãããããããã¨ã®ãã¨ã俺ãããæãã¾ãã
ãã£ã´ããJavaEE DevOps
ã¹ãã¼ã«ã¼ã¯ @nagaseyasuhito æ°ã
Java EE 77ã¨ããJava 8ã®ãããããªãªã¼ã¹ã¨ããã¥ã¼ã¹ã¯èãããã©ãå®éã«ä½¿ã£ã¦ãã¨ãã®è©±ã¨ããéç¨äºä¾ã¨ãã¯ããã¾ããªãæ°ãããã®ã§ã話ããã¨ã«ãããã¨ã®ãã¨ãGREEã§ã®éç¨äºä¾ã¨ãããã¨ã§ã俺ã¯GREEã£ã¦Rubyã¨ãLLè¨èªã®ä¼ç¤¾ã£ã¦ã¤ã¡ã¼ã¸ã ã£ããã§ãããã®ä¸ã®äººããã¨ã³ã¿ã¼ãã©ã¤ãºãã¨ããåã®ã¤ããã®ã使ã£ã¦ãªããä½ã£ããã¨ããã®ã¯ç´ ç´ã«é©ããã
äºä¾ç´¹ä»ã¨ãã¦ã¯ã2013/11/27ã«ä¸ãã£ã¦ã初めてのJava EE 6開発! 最初の壁をどう乗り越えた?──最新Java EE開発“虎の穴” 第1回 菊田洋一氏 - builder by ZDNet Japanããªã¹ã¹ã¡ãã¨ã®ãã¨ã
ãã®çºè¡¨ã§ä½¿ç¨ãããã½ã¼ã¹ã³ã¼ãã¯ã³ãã© http://bit.ly/jjug-camellia
ä½ã£ããã®ã¯ãGlassFishçµç±ã®ã¸ã§ãã¯ã¼ã«ã¼çãªãã®ãJAX-RSã§ãªã¯ã¨ã¹ãæãã¦ãCDIã§ãã¸ãã¯ã«ç¹ãã¦ãJPAã§æ°¸ç¶åãããã¨ãJMSã§ã¡ãã»ã¼ã¸æãããEJB Timerã§éåæå®è¡ãã¢ãªã
JAX-RSã§æãã¦ãCDIã®ãã¸ãã¯ã«ãªãã¦ãJPAã§æ°¸ç¶åãJMSã§ã¡ãã»ã¼ã¸ãªããããã¨ãEJB Iimerã§éåæå®è¡
JAX-RSã®é¨åãLombokãããLombokã@setter,@getter,@EqualsAndHashCodeã¨ããè¦ãã¾ãã¾ã®ãã®ãèªåçæãã¦ããããJAXBã®ã¢ããã¼ã·ã§ã³ããã£ã¼ã«ãã«ã¤ããã¨ãããããåæã«ãã£ã¦ãããã@xmltransientã§é¤å¤ãåå¤æã¯ã©ã¹ã¯ï¼ãã¼ã·ã£ã«ã¨ã¢ã³ãã¼ã·ã£ã«ã®å®è£ )ãæå®ããããªã©ã
Bean Validation @patternã§å®£è¨çã«æ£è¦è¡¨ç¾ãæå®ã
JPAã®criteria APIã使ãâ¦â¦ãã©ã¾ãããã©ãããããããããã§ãã¯ã©ã¤ããªã¢ã®ãã«ãã¼ãããªããããã©ãããããã¼ã¹ã¯ã©ã¹ãä½ã£ã¦ãä¸åã®ã¡ã½ããå¼ã³åºãã§ããããã«ãããã¨ã®ãã¨ããã®è¾ºã¯ã³ã¼ãè¦ãã»ããæ©ããã§ããã£ã¡ãè¦ã¦ããã ããããç¡åã¯ã©ã¹ä½¿ãã®ã§å°ã é·ã ãããªãããã©ã ãå¼ã¤ããã°ä¸è¡ã§çµããã®ã§ãã®ã¡ã®ã¡å¹¸ãã«ãªããããããããªãã
ãµã¼ãã¹ã¯ã©ã¹ãã¯ã©ã¹ã«@transactionalã¤ããã¨ããã¹ã¦ã®ã¡ã½ããããã©ã³ã¶ã¯ã·ã§ã³åä¼ã«ãªãããã®ã¯ã©ã¹ã«ã@injectã§daoã¯ã©ã¹ãæ³¨å ¥ãããã¾ããã¡ã½ããããªãã¼ã·ã§ã³ã§ãã決ã¾ãã®ãã§ãã¯ã³ã¼ããæé¤ããã
ãã¹ããã¦ããããã¹ãã¨ã¤ã³ãã°ã¬ã¼ã·ã§ã³ãã¹ããã©ãåãããã
failsafe-plugin ããã©ã«ãã§ã¯ãã¯ã©ã¹æ«å°¾ã«ITãã¤ãã¦ãããã®ã ããã¹ããããã
surefire-plugin **/*IT.javaãexcludeãã¦å®è¡ãããã
ã³ã³ããã¤ãã£ããã¹ãã¯éãã®ã§ãã§ããã ãã¦ããããã¹ãã«å¯ãã¦ãã¾ãããã
JUnitã§ãentitymanagerfactoryããã¹ãç¨ã®ããããã£ã§èªåã®ã¤ã³ã¹ã¿ã³ã¹ä½ã£ã¦ããã£ã¡ã使ãããã«ãããã§ãJMockitã§entitymangaerãæ³¨å ¥ããã
ã¤ã³ãã°ã¬ã¼ã·ã§ã³ãã¹ããarqullianã使ãããµã¼ãã¹ã¯ã©ã¹ã¨ãã@injectãã¦ãã¹ãããã
ãªãªã¼ã¹ï¼ãããã¤ãgit ã§ãã¼ã¸ã§ã³ç®¡çãã¦ãããmaven-release-pluginã使ãã¨ãèªåçã«ã¿ã°ã¤ããã¦ãããã
ã¦ããããã¹ããITãã¹ããéçºç°å¢ã¸ã®ãããã¤ã¾ã§ã¯èªåã§ãã£ã¦ããããITãã¹ããOkã ã£ãããæåã§ãªãªã¼ã¹ã«ã¯ããã
clone workspace SCMããã段éã§ã®ãªãã¸ããªã®ç¶æ ãã³ãã¼ããããããå½¹ã«ç«ã¤ã®ã¯ãéä¸ã§ã³ãããããããã®ãæ··ãã£ã¦ããããããã¨ãé²ããã
ãããã¤ããã¨ããasadmin deployã³ãã³ã enabled=falseã«ããã¨ãã¾ãGlassFishã®ãã¡ã¤ã³ã«ã®ã¿é åããããã¤ãã«ããªãã¼ã¹ãããã·ããAP1ãå¤ããã¢ã¯ãã£ãããªããªã£ããã¨ãenableã³ãã³ãã§ã¤ã³ã¹ã¿ã³ã¹ãæå®ãã¦ãããã¤ããã次ã¯ãAP1ããã©ãã¦ãAP2ãå¤ãã¦ã以ä¸ç¥ã
éç¨ãã§ã¼ãºãasadmin set-log-levelsããªã³ã©ã¤ã³ã§ãã°ã¬ãã«ãå¤æ´ã§ããããã¨ãã°ããªããéãã¯ã¨ãªãããã¨ããeclipselinkã®ãã°ã¬ãã«ãå¤æ´ããããã¦ãããããã¯ã¨ãªã追ãã
ç£è¦ãJMXã@MXBeanã¨ããã¢ããã¼ã·ã§ã³ãã¤ããã¤ã³ã¿ãã§ã¼ã¹ãã¤ãã£ã¦ãå®è£ ãã¤ãããä»åã¯DBã¢ã¯ã»ã¹ãã¦ã¦ã¼ã¶æ°è² ãããã®ãä½ãããã«EJBã«ãã¦ã@startup, @singletonãã¤ãããã¤ãã·ã£ã©ã¤ãºã§MBeanServerç»é²ãªã©ãªã©ã®å¦çãæ¸ãã
ç£è¦ã¯gangliaã£ã¦ã®ã使ã£ã¦ãã
ã¹ãã¼ãå¤æ´ããã£ãã¨ãã¯ã©ããããï¼ãããã«ã©ã¤ãã§å¯¾å¿ããã¨ãã°ãã«ã©ã åãå¤æ´ï¼name -> userNameï¼ã¨è¨ã£ãå ´åãã¢ããªã±ã¼ã·ã§ã³å´ã§ã¯äºã¤ã®ãã£ã¼ã«ãã«æ¸ãè¾¼ãããã«ããããã®ãã¨ãå¤ããã£ã¼ã«ããæ¶ããã¢ããªããããã¤ããªãããã¨ãã£ãæ段ãã¨ã£ã¦ããã
ã¾ã¨ããã¨ã³ã¿ã¼ãã©ã¤ãºã£ã¦ååããã¯éåãªé¿ããåãããã©ãå®éã¤ãã£ã¦ã¿ããæå¤ã¨ã©ã¤ãã§ã«ã¸ã¥ã¢ã«ã§ãã£ããã¨ã³ã¿ã¼ãã©ã¤ãºã£ã¦ååã¤ãã¦ãæç¹ã§æ絶åå¿ãã人ãå¤ãã ãããã©ã触ã£ã¦ã¿ã¦ãããããããªããã¼ããã¨ãã£ãç· ããããããã³ãã®è¯ãçºè¡¨ã¯èãã¦ã¦é¢ç½ãã£ãã§ãã
æå¾ã«ãã¿ããªâã¨ãã®Advent Calendarã«åå ããã¨ããããããªãããªãã¨ã®ãã¨ã§ããã
Java EE Advent Calendar 2013 - Adventar
GlassFish Advent Calendar 2013 - Adventar