1 / 36

Spring Talk

Spring Talk. Dependency Injection and IoC – Rohit Spring Core Introduction – Rohit Spring Database Connectivity– Lalit Bhatt Introduction to Spring Roo – Rohit. Speaker Introduction. Speaker Introduction. Inversion of Control and Dependency Injection. Example Scenario. Use case.

omar
Download Presentation

Spring Talk

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Spring Talk • Dependency Injection and IoC – Rohit • Spring Core Introduction – Rohit • Spring Database Connectivity– Lalit Bhatt • Introduction to Spring Roo – Rohit

  2. Speaker Introduction

  3. Speaker Introduction

  4. Inversion of Control and Dependency Injection

  5. Example Scenario

  6. Use case Expression Evaluator Output Input (3*4)+sin(cos(30)) 12.15364048

  7. Use case Expression Evaluator Output Input (3*4)+sin(cos(30)) 12.15364048 …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. 10000 input files 10000 output files

  8. Use case Problem Statement - Create a Test framework to test Expression Evaluator with 10,000 expressions

  9. What’s wrong with this code?

  10. ITestCase ITestExecutioner IExpectedDataAdapter IPublisher<R> ILogger<L> IInputAdapter <R> execute(<D>) execute() <D> getInput(index); IntgetCount(); <R> getExpected(index); IntgetCount(); Init(); collect(); publish() log();

  11. If we say new for each arrow, we are coupling components! ITestCase ITestExecutioner IExpectedDataAdapter IPublisher<R> ILogger<L> IInputAdapter <R> execute(<D>) execute() <D> getInput(index); IntgetCount(); <R> getExpected(index); IntgetCount(); Init(); collect(); publish() log();

  12. IExpectedDataAdapter TestExecutioner IPublisher<R> ILogger<L> ITestCase IInputAdapter void setLogger(..) void setTestCase(..) void setInputAdapter(..) void setOutputAdapter(..) void setResultPublisher(…) void execute() <D> getInput(index); IntgetCount(); <R> getExpected(index); IntgetCount(); Init(); collect(); publish() <R> execute(<D>) log();

  13. Lets see this in Code

  14. Spring Core

  15. More Theory of Spring Core • Constructor Dependency Injection • Setter Dependency Injection • Auto Wiring • Bean Scope • Lazy Init • Initiating Spring Framework

  16. Constructor Injection <!-- IInputAdapter, IExpectedDataAdapter Implementation --> <bean id="testDataAdapter" class="com.design.di.production.TestDataAdapter"> <constructor-arg type="java.lang.String" value="testdata.csv"/> </bean>

  17. Setter Injection <!-- Executioner Implementation --> <bean id="executioner" class="com.design.di.production.ActualExecutioner"> <property name="resultPublisher"> <ref bean="csvPublisher"/> </property> …. </bean>

  18. Auto Wiring Requirement - All my beans require a logger. Q – Do I explicitly put logger ref in all beans? A – No, Use Auto Wiring

  19. Autowire Types

  20. Auto Wiring <bean id="csvPublisher" class="com.design.di.production.CSVPublisher" autowire=“autodetect”> <property name="filePrefix" value="result"> </property> <property name="logger"> <refbean="consoleLogger"/> </property> </bean>

  21. Bean Scope

  22. Bean Scope <!-- Logger Implementation --> <bean id="consoleLogger" class="com.design.di.production.ConsoleLogger” scope=“prototype”> <property name="level"> <value type="com.design.di.ILogger$Level"> Info </value> </property> </bean>

  23. Lazy Init

  24. Lazy Init <!- - Created at first access - -> <bean id="lazy" class="com.foo.ExpensiveToCreateBean” lazy-init="true"/> <!- - Created an at startup - -> <bean name="not.lazy" class="com.foo.AnotherBean"/>

  25. Initiating Spring Framework

  26. Conclusion Why use Spring • Modular Application Development – Maximum reuse • Configuration based Application Development • TDD possible using mock objects • Integration testing by stubbing out production modules

  27. Introduction to Spring Roo

  28. Scope of this talk • Understanding Rapid App Development • Demo Spring Roo • Excite you guys to take a session on Roo

  29. Rapid Application Development Generated Code Adapts to new inputs Configuration Burden Commands for Convention No Lock In Extensible

  30. Code Demo Time

  31. Typical Application Flow Define Entities Security CRUD DAOs Application Logic DAO Unit Test cases Integration Tests Web Controller Deploy Controller Test Cases

  32. Roo Commands $>roo.sh $roo> project --topLevelPackagecom.test.roo $roo> persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY $roo> entity --class ~.model.Employee–testAutomatically $roo> field string --fieldNamefirstName --notNull $roo> field string --fieldNamelastName–notNull $roo> controller all --package ~.web $roo> json all $roo> exit $>mvn package tomcat:run

  33. http://localhost:8080/roo

  34. Q & A? Contact us at rohitsghatol@gmail.com

More Related