Guice vs. SpringJavaConfig (5) Conclusions
Guice vs. Spring JavaConfig: A comparison of DI styles
DIã¹ã¿ã¤ã«ã®æ¯è¼ï¼Guice 対 Springã®Javaã³ã¼ãã³ã³ãã£ã°
http://jroller.com/page/habuma?entry=guice_vs_spring_javaconfig_aâ [翻訳]Guice vs. SpringJavaConfig (1) A Knight's tour of Guice
â [翻訳]Guice vs. SpringJavaConfig (2) Guice and AOP
â [翻訳]Guice vs. SpringJavaConfig (3) A Knight's tour of Spring JavaConfig
â [翻訳]Guice vs. SpringJavaConfig (4) Spring JavaConfig and AOP
Conclusions
Both Guice and Spring JavaConfig offer interesting alternatives to the sometimes verbose XML used to configure many frameworks (including Spring). Each, however, takes a different approach to configuration. Let's examine how they stack up against each other:
ã¾ã¨ã
Guiceã¨Spring JavaConfigã¯ãå
±ã«é¢ç½ãææ¡ããã¦ãã¾ãããã®ææ¡ã¨ã¯ãå¤ãã®ãã¬ã¼ã ã¯ã¼ã¯ï¼Springãå«ãï¼ã§è¨å®ã«ä½¿ããã¦ããæã«åé·ãªXMLã¸ã®ä»£æ¿æ¡ã§ããã©ã¡ãããããããªããè¨å®æ¹æ³ã¨ãã¦ã¯éã£ãã¢ããã¼ããåã£ã¦ãã¾ããããããäºãã®æ¯è¼ãããè¦ã¦ã¿ã¾ãããã
- String identifiers - One complaint against Spring's XML configuration is the use of String identifiers and the lack of refactorability therein. It's true, that Spring's XML configuration is heavy with references to classes, properties, and other beans that are merely String values and thus difficult to refactor without a proper tool (such as the SpringIDE for Eclipse). Fortunately, both Guice and Spring JavaConfig register a win in this category, as neither relies on String identifiers in their configuration and both are easily refactorable through modern IDEs.
- æååã«ããèå¥åãSpringã®XMLè¨å®ãã¡ã¤ã«ã«å¯¾ãã1ã¤ã®æ¹å¤ã¯ãæååã«ããèå¥åã使ã£ã¦ãããã¨ã¨ããã®ãã¨ã«ãã£ã¦ãªãã¡ã¯ã¿ãªã³ã°ã®ãããããæãªããã¦ãããã¨ã§ãã確ãã«ãSpringã®XMLã³ã³ãã£ã°ãã¡ã¤ã«ã¯ãã¯ã©ã¹ãããããã£ã¼ããããä»ã®Beanãåç §ããã®ãé¢åã§ãããã åãªãæååå¤ã§ãããããããã«é©åãªãã¼ã«ï¼Eclipseã®SpringIDEã®ãããªï¼ã使ããªãå ´åã«ãªãã¡ã¯ã¿ãªã³ã°ãé£ãããªã£ã¦ãã¾ãã幸ãã«ããGuiceã¨Spring JavaConfigã¯å ±ã«ãã®ã«ãã´ãªã¼ã«å¯¾ãã¦ã¯å¹ãç®ãããã¾ãã両æ¹ã¨ãããããã®ã³ã³ãã£ã°ã¬ã¼ã·ã§ã³ã«ããã¦æååã«ããèå¥åã«é ¼ãããæè¿ã®IDEã使ãã°ç°¡åã«ãªãã¡ã¯ã¿ãªã³ã°ã§ããããã«ãªã£ã¦ãã¾ãã
- Speed/Performance - Guice bills itself as faster than other containers when performing dependency injection. While I didn't run any formal benchmarks to compare Spring JavaConfig and Guice, some informal tests proved Guice's claims to be true. This is not terribly surprising, however, as Spring defines a rich set of lifecycle events around the creation of beans in the container, while I could not find any comparable lifecycle built into Guice. Without the overhead of the lifecycle events, Guice does, in fact, wire up the beans much faster than Spring.
- ã¹ãã¼ã/ããã©ã¼ãã³ã¹ãGuiceã¯Dependency Injectionã®å¦çã«ã¤ãã¦ä»ã®ã³ã³ãããããéãã¨èªåã§å®£ä¼ãã¦ãã¾ããããããå ¬å¼ã®ãã³ããã¼ã¯ã§ã¯ãã£ãããã§ã¯ãªãã§ãããSpring JavaConfigã¨Guiceãæ¯è¼ããã¨ãããããã¤ãã®éå ¬å¼ãã¹ãã§ã¯Guiceã®ä¸»å¼µãæ£ãããã¨ããããã¾ãããããã¯ãããã»ã©é©ããã¨ã§ãããã¾ãããããããªãããSpringã¯ãã³ã³ããã§Beanãçæãããã¨ã«é¢ããè±å¯ãªã©ã¤ããµã¤ã¯ã«ã¤ãã³ãé¡ããã£ã¦ãã¾ããGuiceã§ã¯ãããã«ç¸å½ããæ©è½ãã¿ã¤ãããã¨ãã§ãã¾ããã§ãããã©ã¤ããµã¤ã¯ã«ã¤ãã³ãã®ãªã¼ãã¼ãããããªãã®ã§ãGuiceã¯ãå®éã®ã¨ãããBeanã®ç´ä»ããSpringãããéãã§ãã
- JAR file footprint - The Guice example above only requires two JAR files: guice-1.0.jar and aopalliance.jar. Together, these two JAR files weigh in at just over half a megabyte. Meanwhile, the Spring example requires several JAR files, including spring-javaconfig.jar, spring-beans.jar, spring-aop.jar, spring-core.jar, spring-context.jar, commons-logging.jar, aopalliance.jar, asm-2.2.2jar, cglib-nodep-2.1_3.jar, and aspectjweaver.jar, together weighing in at several megabytes in size. So, Guice is more lightweight than Spring in terms of JAR file footprint.
- JARãã¡ã¤ã«è¶³è·¡ãåè¿°ã®Guiceã®ãµã³ãã«ã§ã¯ã guice-1.0.jar 㨠aopalliance.jar ã®ãã£ãäºã¤ã®JARãã¡ã¤ã«ã ããå¿ è¦ã§ããããããã®ï¼ã¤ã®JARãã¡ã¤ã«ã¯ãééã500KByteã»ã©ããããã¾ãããä¸æ¹Springã®ãµã³ãã«ã¯ãããã¤ãã®JARãã¡ã¤ã«ãå¿ è¦ã¨ãã¾ãããããã¯ãspring-javaconfig.jar, spring-beans.jar, spring-aop.jar, spring-core.jar, spring-context.jar, commons-logging.jar, aopalliance.jar, asm-2.2.2jar, cglib-nodep-2.1_3.jar, and aspectjweaver.jarã§ãããããã®ããã¤ãã¯ã¡ã¬åä½ã®ãµã¤ãºã§ããããã§ãGuiceã¯JARãã¡ã¤ã«ã®ç¹ã§ã¯Springããã軽éã§ã
- Non-intrusive - Both Spring JavaConfig and Guice rely on proprietary annotations to help them do their injections. Where they differ, however, is that Guice requires placement of @Inject annotations withing the injected application classes, while Spring JavaConfig confines its use of annotations to the configuration-specific classes. Consequently, Guice-injected classes cannot be reused and compiled in a separate application without the Guice JAR file in place. Meanwhile, Spring JavaConfig leaves the application classes unaltered, enabling their unhindered reuse. Thus, in this category, Spring JavaConfig is the clear winner. (Granted, Spring does define a handful of annotations to be placed in application classes--@Required and @Transactional come to mind. But their use is not mandated to configure Spring.)
- ç ©ããããªããSpring JavaConfigã¨Guiceã®ä¸¡æ¹ã§ãã¤ã³ã¸ã§ã¯ããè£å©ããããã«ç¬èªä»æ§ã®ã¢ããã¼ã·ã§ã³ã«ä¾åãã¾ããããããªãããSpring JavaConfigã¨Guiceã®ããããã®éãã¯ãGuiceã¯@Injectã¢ããã¼ã·ã§ã³ãã¤ã³ã¸ã§ã¯ããããã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ã¨ä¸ç·ã«é ç½®ããªãã¦ã¯ãªããªãã®ã«å¯¾ãã¦ãSpring JavaConfigã¯ã¢ããã¼ã·ã§ã³ã®ä½¿ç¨ãã³ã³ãã£ã°ã¬ã¼ã·ã§ã³ç¹æã®ã¯ã©ã¹ã«å¶éãã¾ãããã®çµæGuiceã使ã£ãå ´åãç°ãªãã¢ããªã±ã¼ã·ã§ã³ã§ãGuice JARãã¡ã¤ã«ãé ç½®ããã«ã¯ã¤ã³ã¸ã§ã¯ããããã¯ã©ã¹ãåå©ç¨ã®ããã«ã³ã³ãã¤ã«ãããã¨ãã§ãã¾ããããããã¦ãéã«ãSpring JavaConfigã¯ã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ãå¤æ´ããæ®ãã¾ãããã®ããåå©ç¨ã妨害ãã¾ããããããã£ã¦ããã®ã«ãã´ãªã§ã¯ãSpring JavaConfigã®å®åã§ãã(ä¸ãã¦ãSpringã¯ã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ã«é ç½®ãããããã¤ãã®ã¢ããã¼ã·ã§ã³ãå®ç¾©ãã¦ãã¾ãããã¨ãã°ã@Requiredã@Transactionalãæãæµ®ãã³ã¾ãã ãããããããã¯Springã使ããªãã¦ãå©ç¨å¯è½ã§ã)
- Third-party beans - Related to the last category, I could find no direct way to inject values into a third party class using Guice. Guice-style injection requires the use of the @Inject annotation, which is useless in classes for which I do not have the source code (or classes that I do not wish to annotate with @Inject). Guice's documentation indicates that third-party components will require the creation of a custom provider, but in my opinion, this is a hack that adds complexity to something that would be very simple if the @Inject annotation were not required. Spring JavaConfig, however, keeps the configuration separate from the application classes, thus wiring a third-party class in Spring JavaConfig is no different than wiring a custom class. Spring wins again.
- ãµã¼ããã¼ãã£ã¼ã®Beanãæå¾ã®ã«ãã´ãªã¼ã«ãé¢é£ãã¾ãããGuiceã使ã£ã¦ãµã¼ããã¼ãã£ã¼ã®ã¯ã©ã¹ã«å¤ãã¤ã³ã¸ã§ã¯ãããç´æ¥çãªæ¹æ³ãè¦ã¤ãããã¨ãã§ãã¾ããã§ãããGuiceæ¹å¼ã®ã¤ã³ã¸ã§ã¯ã·ã§ã³ã¯ã@Injectã¢ããã¼ã·ã§ã³ã®å©ç¨ãå¿ è¦ã¨ãã¾ãããã®ãããã½ã¼ã¹ã³ã¼ããæã£ã¦ããªããããªã¯ã©ã¹ï¼ã¾ãã¯ãï¼ Injectã§ã¢ããã¼ãããããªããããªã¯ã©ã¹ï¼ã«å¯¾ãã¦ã¯å½¹ã«ç«ã¡ã¾ãããGuiceã®ããã¥ã¡ã³ãã¯ããµã¼ããã¼ãã£ã¼ã³ã³ãã¼ãã³ãã使ãå ´åã¯ãã«ã¹ã¿ã ãããã¤ãã¼ãä½ããã¨ãå¿ è¦ã¨ããã¨è¨è¿°ãã¦ãã¾ããããããç§ã®æè¦ã¨ãã¦ããã®æ¹æ³ã¯ããã@Injectã¢ããã¼ã·ã§ã³ãå¿ è¦ã§ãªãã£ãã¨ãã¦ããã¨ã¦ãã·ã³ãã«ã«ããããã®ã«å¯¾ãã¦ãè¤éããå¢ãã¦ãã¾ãã¾ããããããªããSpringãJavaConfigã§ã¯ãã³ã³ãã£ã°ã¬ã¼ã·ã§ã³ãã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ããåé¢ãã¦ãã¾ããããããã«ãSpring JavaConfigã使ã£ã¦ããµã¼ããã¼ãã£ã¼ã®ã¯ã©ã¹ã¸ã®ç´ä»ãã使ããã¨ã¯ãã«ã¹ã¿ã ã¯ã©ã¹ã«å¯¾ãã¦ç´ä»ãã使ããã¨ã«å¯¾ãã¦ãããããéãã¯ããã¾ãããSpringããã¾ããåå©ã§ãã
- Constant/literal injection - Injecting a String literal (or any other type of literal value) in Spring JavaConfig is rather straightforward. In contrast, literal injection in Guice is cumbersome, requiring the creation and use of a custom annotation to identify where the literal should be injected. Spring JavaConfig wins this category.
- ã³ã³ã¹ã¿ã³ã/ãªãã©ã« ã¤ã³ã¸ã§ã¯ã·ã§ã³ãSpring JavaConfigã«ããã¦æååã®ãªãã©ã«ï¼ããã³ãã®ä»ã®åã®ãªãã©ã«å¤ï¼ãã¤ã³ã¸ã§ã¯ããããã¨ã¯ãããç´ ç´ã§ããããã«å¼ãæããGuiceã§ã®ãªãã©ã«ã®ã¤ã³ã¸ã§ã¯ã·ã§ã³ã¯ããªãã©ã«ãã¤ã³ã¸ã§ã¯ããããå ´æãèå¥ããããã«ã«ã¹ã¿ã ã¢ããã¼ã·ã§ã³ã使ãã¨ãããåµä½ãå¿ è¦ã¨ããã®ã§æ±ãã«ããã®ã§ãããã®ã«ãã´ãªã¼ã§ã¯Spring JavaConfigã®åã¡ã§ãã
- AOP - The Guice documentation acknowledges that Guice's flavor of AOP is less powerful than Spring AOP (both of which are much less powerful than AspectJ). But, the Guice documentation claims that this loss of AOP power is in trade for simplicity. Honestly, I found Guice's approach to AOP (binding interceptors) non-intuitive as compared to Spring JavaConfig. The Spring JavaConfig approach required only a simple annotation with an AspectJ-style pointcut expression, whereas Guice required a confusing binding call involving "matchers" to pick out the target of the interceptor. Maybe I'm too well-versed in Spring AOP to appreciate the simplicity of Guice's interceptor-binding...but for now I must give Spring the win in this category.
- AOPãGuiceã®ããã¥ã¡ã³ãã¯ãGuiceã®AOPã¯ãSpringAOPãããã¯ã¼ã¯å£ãã¨èªãã¦ãã¾ããï¼AspectJã®AOPã«å¯¾ãã¦ãå£ãã¾ãï¼ããããGuiceã®ããã¥ã¡ã³ãã¯ãAOPã®ãã¯ã¼ã®ãã¹ã¯ã·ã³ãã«ãã¨ã®ãã¬ã¼ãã ã¨ä¸»å¼µãã¦ãã¾ããæ£ç´ã«ãç§ã¯Guiceã®AOPã®ã¢ããã¼ãï¼ã¤ã³ã¿ã¼ã»ãã¿ã¼ã®ãã¤ã³ãï¼ã¯ãSpring JavaConfigã«æ¯ã¹ã¦ç´æçã§ã¯ãªãã¨æãã¾ãããSpring JavaConfigã®ã¢ããã¼ãã¯ãã·ã³ãã«ãªã¢ããã¼ã·ã§ã³ãè¦æ±ããã ãã§ãããã®ã¢ããã¼ã·ã§ã³ã¨ã¯ãAspectJæ¹å¼ã®ãã¤ã³ãã«ããã®è¨è¿°å¼ã使ãã¾ããããã«å¯¾ãã¦ãGuiceã¯ã¤ã³ã¿ã¼ã»ãã¿ã¼ã®å¯¾è±¡ãè¦ã¤ãåºãããã®"matchers"ãä¼´ããåããã«ãããã¤ã³ãã£ã³ã°ã®å¼ã³åºããå¿ è¦ã¨ãã¾ãããã¶ããGuiceã®ã¤ã³ã¿ã¼ã»ãã¿ã¼ãã¤ã³ãã®ã·ã³ãã«ãã«ä¾¡å¤ãèªããããã«ã¯ãç§ã¯SpringAOPã«ç²¾éãããã¦ãã¾ãããããããã®ã«ãã´ãªã¼ã§ã¯Springã«åå©ãä¸ããããå¾ã¾ããã
Final score: Guice - 3, Spring JavaConfig - 5.
æçµçãªã¹ã³ã¢ï¼ Guice-3ãSpring JavaConfig-5
I'm glad that I spent the time to learn a little about Guice, but I'm not all that "juiced" about using Guice. In addition to all of the reasons given above, I'd much rather build my application against a well-established container like Spring that has a wealth of integration points with other frameworks and APIs (Guice only has integration with Struts 2 and Spring, as far as I can tell). Also, to be clear, Guice really doesn't compete with Spring as much as it competes with Spring's application context--Spring's capabilities go beyond dependency injection and AOP.
ç§ã¯Guiceã«é¢ãã¦å°ãå¦ã¶æéãéããããã¨ãããããæãã¾ããããããGuiceã使ç¨ãããã¨ã§ã¯ãããã»ã©ãJuiceããçµããã¾ããã§ãããä¸è¨ã«ç¤ºããããã¹ã¦ã®çç±ã«å ãã¦ãç§ã¯ç§ã®ã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ããã®ã«ããããSpringã®ããã«å°ä½ã確ç«ãã¦ãã¦ãä»ã®ãã¬ã¼ã ã¯ã¼ã¯ã¨è±å¯ãªçµ±åãã¤ã³ããæã£ã¦ããAPIããã¤ã³ã³ããã使ã£ã¦ã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ããã§ãããã(Guiceã«ã¯ãç§ãå¤æãããã¨ãã§ããéãStruts2ã¨Springã¨ã®çµ±åãããã ãã§ã)ã ã¾ãã¯ã£ããè¨ã£ã¦ãGuiceã¯å®ã¯Springã¨ãSpringã®ã¢ããªã±ã¼ã·ã§ã³ã³ã³ããã¹ãã¨ç«¶åããã¨ããã»ã©ã§ãããã¾ãã--Springã®è½åã¯Dependency Injectionã¨AOPãè¶ãã¦ãã¾ãã
Also, one more comment on the speed issue: I've given Guice a point in that category, simply because my quick-n-dirty tests confirmed that Guice was faster. But, I've seen a few more detailed performance tests run by others that show that while Guice is faster in creating prototype beans, Spring is faster in creating singletons. Given that singletons are more typically used than prototypes, Spring should probably get the point in this category. But since I have not taken the time to provide the evidence, I'll go ahead and give this one to Guice.
ã¹ãã¼ãã®åé¡ã«ãããã²ã¨ã¤ã®ã³ã¡ã³ããå ãã¾ããåã«ç§ã®ãå³èã§ä¿¡é ¼ã§ããªããã¹ãã§ã¯ãGuiceã®æ¹ãéãã¨ç¢ºèªããã®ã§ããã®ã«ãã´ãªã§ã¯ãã¤ã³ããGuiceã«ä¸ãã¾ããã ããããç§ã¯ãä»ã®è©³ç´°ãªæ§è½ãã¹ããèµ°ãããã¨ãããGuiceã¯ãããã¿ã¤ãBeanãä½æãã¦ããéã«ãããéãSpringã¯ã·ã³ã°ã«ãã³ãä½ãã®ã«ããéãã®ã示ããã®ãããã¾ãããã·ã³ã°ã«ãã³ããããã¿ã¤ãããä¸è¬çã«ä½¿ç¨ããã¦ãããªããSpringã¯ãã¶ããã®ã«ãã´ãªã§ãã¤ã³ããå¾ãã¹ãã§ãã ãããã証æ ãæä¾ããããã«æéãããã¦ããªãã®ã§ãç§ã¯ãGuiceã«é æ
®ãªããã¤ã³ããä¸ãã¾ããã
(I'm sure that you're wondering where the numbers are that show Spring is faster in producing singletons. Unfortunately, the work done to produce these numbers is not mine and I am not sure if the author is ready to release his figures yet. If he's reading this, then he knows I'm talking about him here and I ask him to provide the numbers on his blog. When/if he does that, I'll put the link to his blog here.)
(æ°åä¸ã¯ãSpringã¯ã·ã³ã°ã«ãã³ãçç£ããã®ããããéãã¨ãããã¨ã表ãã¦ããã¨ãããã¨ã«é©ããã¨ç¢ºä¿¡ãã¦ãã¾ãã æ®å¿µãªããããããã®æ°åãçç£ããããã«è¡ãããä»äºã¯ç§ã®æ
å½ã§ã¯ããã¾ãããããã¦ãç§ã¯ä½è
ãã¾ã ãã¼ã¿ãçºè¡¨ãã¦ããªããã¨ã«é¢ãã¦ãæºåãã§ãã¦ãããã©ããã確信ãã¦ãã¾ããããããèªãã§ãããªããå½¼ã¯ç§ãããã§å½¼ã«é¢ãã¦è©±ãã¦ããã®ãç¥ã£ã¦ãã¾ããããã¦ãç§ã¯å½¼ã®ããã°ã§æ°åãæä¾ããããã«å½¼ã«é ¼ãã§ãã¾ããå½¼ãããããããªããããã§å½¼ã®ããã°ã«ãªã³ã¯ãå¼µãã¤ããã§ãã)
Again, let me repeat that I've had only a few days worth of experience with Guice as compared to a few years of experience with Spring. If there's a change that can be made to the Guice examples to make them better and to provide a more fair comparison, I'm eager to hear about it.
ããä¸åº¦ãç¹°ãè¿ãã¦è¨ããã¦ããã ãã¾ãããæ°æ¥ã®Guiceã®çµé¨ã§ãSpringã®æ°å¹´ã®çµé¨ã¨æ¯ã¹ã¦åããããã®é常ã«ä¾¡å¤ã®ããçµé¨ããã¾ãããããå
¬æ£ãªæ¯è¼ãã§ãããããªãGuiceã®ãµã³ãã«ã«ããããã®ã¢ãããã¼ãããããã¨ããç§ã¯é常ã«å¾
ã¡æãã§ãã¾ãã
Special thanks to Crazy Bob for his gracious offer to review my Guice example. He pointed out a few things about my example that could've been done a bit better. He also suggested moving the ".in(Scopes.SINGLETON)" part of the binding into the HolyGrailQuest and KnightOfTheRoundTable classes as a class-scoped @Singleton annotation. I chose not to do this, because it would be one more intrusion of Guice into my application objects. Finally, Bob wanted me to mention that Guice really shines when you use a dependency more than once (in the knight/quest example, the Quest dependency was only used once).
Crazy Bobã«é常ã«æè¬ãã¾ããç§ã®Guiceãµã³ãã«ã®ã¬ãã¥ã¼ã«è¦ªåãªãªãã¡ã¼ãããã ãã¾ãããå½¼ã¯ãç§ã®ãµã³ãã«ãã¡ãã£ã¨ã ãè¯ããããããªãããã¤ãã®ææãããã¾ãããå½¼ã¯ãã¾ã".in(Scopes.SINGLETON)"ã移åããããã«ææ¡ãã¦ããã¾ããã ã¾ãå½¼ã¯ãã¯ã©ã¹ãç¯å²ã¨ãã@Singletonã¢ããã¼ã·ã§ã³ã¨ãã¦ãHolyGrailQuestã¨KnightOfTheRoundTableã®ã¯ã©ã¹ã«ãã¤ã³ãã£ã³ã°ã®ã.in(Scopes.SINGLETON)ãã®é¨åãåããããææ¡ãã¦ããã¾ããç§ã®ã¢ããªã±ã¼ã·ã§ã³ãªãã¸ã§ã¯ãã«Guiceããã1ã¤ã®é¨åã§å æ ãã¦ãããã¨ã«ãªãããããããã¾ããã§ãããããæçµçã«Bobã¯
ç§ã«ãGuiceã¯ä¸å以ä¸ã®ä¾åæ§ã使ç¨ããã¨ããæ¬å½ã«å
ãè¼ãã¨è¨ã£ã¦æ¬²ããã£ãããã§ãã(knight/questã®ãµã³ãã«ã§ã¯ãQuestã®ä¾åæ§ã¯ä¸åº¦ä½¿ç¨ãããã ãã§ã)
Thanks also go to Rod Johnson, Colin Sampaleanu, and Costin Leau for going over the Spring JavaConfig bits and providing their feedback. Rod suggested that I mention that the @AspectJ advice style is way nicer than the AOP Alliance stuff (which is basically a legacy programming model in Spring 2.0). I fully agree that the @AspectJ stuff is pretty slick and I recommend it over the AOP Alliance stuff. I only used the AOP Alliance stuff here to provide a slightly more even playing field. (Although, in hindsight, an @AspectJ example would've been a slam-dunk in Spring's favor.)
ã¾ããRod Johnsonã Colin Sampaleanuãããã³Costin Leauã«æè¬ãã¾ããSpring JavaConfigã®å
·ä½ä¾ã調ã¹ã¦ããããã®ãã£ã¼ãããã¯ãæä¾ãã¦ããã¾ããããããã¯ãç§ã@AspectJ ã¢ããã¤ã¹ã¹ã¿ã¤ã«ãAOP Allianceã§ã®AOPæ©è½(åºæ¬çã«Spring2.0ã®ã¬ã¬ã·ã¼ããã°ã©ãã³ã°ã¢ãã«ã§ãã)ãããã£ã¨è¯ãã¨è¿°ã¹ã¦ããã¾ãããç§ã¯ã@AspectJã®AOPæ©è½ã¯é常ã«ãã°ãããã®ã§ãAOP Allianceã®AOPæ©è½ã§ã¯ãªãã@AspectJãæ¨è¦ããã®ã«è«¸æãæãã¦è³æã§ããç§ã¯ããããã«å
¬å¹³ãªéã³å ´ãæä¾ããã®ã«ãããã§AOP Allianceã®AOPæ©è½ã使ç¨ããã ãã§ãã (ã¨ã¯ãããå¾ããèããã¨@AspectJã®ä¾ã ã£ããSpringå´ã«ç¢ºå®ã«æå©ã ã£ãã§ãããã)
Finally, and before I get pointless comments to this effect: I realize that a "Knight's Tour" is a series of 64 moves by a knight piece on a chess board, where the knight visits every square once and only once. Had I given an actual "knight's tour" of Guice and Spring, my examples would've been more comprehensive (covering at least 64 points). I know the phrase isn't a perfect fit here, but it sounds cool, so I'm keeping it. :-)
çµæã¨ãã¦ã以åãç§ã¯ä»¥ä¸ã®ãããªè¶£æ¨ã§ç¡æå³ãªã³ã¡ã³ããå¾ã¾ããã
ç§ã¯æãåºãã¾ããããKnight's Tourãã¯ãã§ã¹ç¤ã®ä¸ã®ãã¤ãã®é§ã«ãã64åã®ç§»åã§ããããã¤ãã¯ãã¹ã¦ã®å ´æã«æä½1åãæé«1åã ã移åãããã¨ãã§ãã¾ããGuiceã¨Springã®å®éã®ãKnight's Tourããä¸ãããªããç§ã®ä¾ã§ã¯ãããå
æ¬çã§ãã(å°ãªãã¨ã64ãã¤ã³ããã«ãã¼ãã¦ãã¾ã)ããã®ãã¬ã¼ãºãããã§ã®å®å
¨ã«ãã£ããããªããã¨ãç¥ã£ã¦ãã¾ããããããã¯ã¼ã«ã«èãããã®ã§ããã®ã¾ã¾ã«ãã¨ãã¾ãã :-)
And, in case you didn't catch those download links earlier, you can find the Guice example code here and the Spring JavaConfig example code here.
ãããããä¸ãä¸ããããã®ãã¦ã³ãã¼ããªã³ã¯ãç°¡åã«è¦ã¤ãããã¨ãã§ããªãã¨ãã®ããã«ãGuiceã®ãµã³ãã«ã³ã¼ãã¯ããã«ãããSpringJavaConfigã®ãµã³ãã«ã³ã¼ãã¯ã ããã«ããã¾ãã