SlideShare a Scribd company logo
1 of 14
JSUG 第 2 回ライトニングトーク Google Guice モンスター・ラボ 稲村創( so.inamura@monstar-lab.com) 音楽配信サイト: http://monstar.fm ブログ: http:// d.hatena.ne.jp/arumani /
Guice とは ,[object Object],[object Object],[object Object],[object Object]
Guice の特徴 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3ステップ DIサンプル ,[object Object],public class Client { @Inject private Service service; @Inject public Client(Service service) { this.service = service; } @Inject public void injectMethod(Service service) { this.service = service; }  }
3ステップ DIサンプル ,[object Object],public class MyModule extends AbstractModule { protected void configure() { // Service という型があったら、 ServiceImpl クラスを inject する bind( Service.class ).to( ServiceImpl.class ); } }
3ステップ DIサンプル ,[object Object],public static void main(String[] args) { Injector injector = Guice.createInjector(new MyModule()); Client client =   injector.getInstance(Client.class); client.execute(); }   ⇒ DI 済インスタンス取得!
3ステップ AOPサンプル ,[object Object],// AOP Alliance のインタフェースを使ったインターセプタを実装 public class LoggingInterceptor  implements MethodInterceptor  { public Object invoke(MethodInvocation methodInvocation) throws Throwable { System.out.println("AOP から出力 "); //  本来の処理を実行 return methodInvocation.proceed(); } }
3ステップ AOPサンプル ,[object Object],protected void configure() { bind(Service.class).to(ServiceImpl.class); bindInterceptor( //  対象クラス(この例はパッケージ一括指定) inPackage(Service.class.getPackage()) //  対象メソッド(この例は全メソッド指定) , any() //  インターセプタ , new LoggingInterceptor()); }
3ステップ AOPサンプル ,[object Object],public static void main(String[] args) { Injector injector = Guice.createInjector(new MyModule()); Client client =  injector.getInstance(Client.class); client.execute(); }   ⇒ weave 済インスタンス取得!
Spring連携サンプル // Spring コンテナ作成 ApplicationContext context =  new ClassPathXmlApplicationContext(&quot;context.xml&quot;); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(BeanFactory.class).toInstance(context);  // context.xml に //  <bean id= “ foo ”  class=“ FooImpl ” /> //  と書いてあるとして bind( Foo.class ).toProvider(fromSpring( Foo.class,  “foo&quot; ) ); } });
FAQ ,[object Object],[object Object],[object Object],[object Object]
FAQ ,[object Object],[object Object],[object Object]
リンク ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]

More Related Content

Viewers also liked

NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008Oyvind Solstad
 
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワークTakatsugu Shigeta
 
I Want More Traffic Now!
I Want More Traffic Now!I Want More Traffic Now!
I Want More Traffic Now!Karim Gargum
 
Lug Roma3 Corso Linux Base
Lug Roma3   Corso Linux BaseLug Roma3   Corso Linux Base
Lug Roma3 Corso Linux Basefosk
 
Portfolio interoperability progress in the UK
Portfolio interoperability progress in the UKPortfolio interoperability progress in the UK
Portfolio interoperability progress in the UKSimon Grant
 
Deprivileging The Digital
Deprivileging The DigitalDeprivileging The Digital
Deprivileging The DigitalTony McNeill
 
Polygons
PolygonsPolygons
Polygonspotc
 
Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Oyvind Solstad
 
Platfrom for community-based solutions
Platfrom for community-based solutionsPlatfrom for community-based solutions
Platfrom for community-based solutionsLatte Media
 
Durmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga DevamDurmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga Devammillitrk
 

Viewers also liked (20)

NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008NRKbeta - Webdagene 2008
NRKbeta - Webdagene 2008
 
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワーク
 
I Want More Traffic Now!
I Want More Traffic Now!I Want More Traffic Now!
I Want More Traffic Now!
 
Lug Roma3 Corso Linux Base
Lug Roma3   Corso Linux BaseLug Roma3   Corso Linux Base
Lug Roma3 Corso Linux Base
 
Portfolio interoperability progress in the UK
Portfolio interoperability progress in the UKPortfolio interoperability progress in the UK
Portfolio interoperability progress in the UK
 
Deprivileging The Digital
Deprivileging The DigitalDeprivileging The Digital
Deprivileging The Digital
 
Quote Presentation2
Quote Presentation2Quote Presentation2
Quote Presentation2
 
building BRIDGES
building BRIDGESbuilding BRIDGES
building BRIDGES
 
Future Shapers.Ppt
Future Shapers.PptFuture Shapers.Ppt
Future Shapers.Ppt
 
PR30
PR30PR30
PR30
 
Guimãraes (Portugal)
Guimãraes (Portugal)Guimãraes (Portugal)
Guimãraes (Portugal)
 
Polygons
PolygonsPolygons
Polygons
 
Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)Mashups - webforum 2009 (Øyvind Solstad)
Mashups - webforum 2009 (Øyvind Solstad)
 
Ma ed 2014
Ma ed 2014Ma ed 2014
Ma ed 2014
 
A/B Testing 101
A/B Testing 101A/B Testing 101
A/B Testing 101
 
Platfrom for community-based solutions
Platfrom for community-based solutionsPlatfrom for community-based solutions
Platfrom for community-based solutions
 
Oporto
OportoOporto
Oporto
 
No phai tra 4
No phai tra   4No phai tra   4
No phai tra 4
 
Durmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga DevamDurmak Yok Yolsuzluga Devam
Durmak Yok Yolsuzluga Devam
 
NCE Tourism Bergen
NCE Tourism BergenNCE Tourism Bergen
NCE Tourism Bergen
 

Recently uploaded

[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 

Recently uploaded (10)

[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 

Google Guice - JSUG第2回勉強会ライトニングトーク

  • 1. JSUG 第 2 回ライトニングトーク Google Guice モンスター・ラボ 稲村創( so.inamura@monstar-lab.com) 音楽配信サイト: http://monstar.fm ブログ: http:// d.hatena.ne.jp/arumani /
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Spring連携サンプル // Spring コンテナ作成 ApplicationContext context = new ClassPathXmlApplicationContext(&quot;context.xml&quot;); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(BeanFactory.class).toInstance(context); // context.xml に // <bean id= “ foo ” class=“ FooImpl ” /> // と書いてあるとして bind( Foo.class ).toProvider(fromSpring( Foo.class, “foo&quot; ) ); } });
  • 11.
  • 12.
  • 13.
  • 14.