360 likes | 515 Views
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.
E N D
Spring Talk • Dependency Injection and IoC – Rohit • Spring Core Introduction – Rohit • Spring Database Connectivity– Lalit Bhatt • Introduction to Spring Roo – Rohit
Use case Expression Evaluator Output Input (3*4)+sin(cos(30)) 12.15364048
Use case Expression Evaluator Output Input (3*4)+sin(cos(30)) 12.15364048 …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. …………………………. 10000 input files 10000 output files
Use case Problem Statement - Create a Test framework to test Expression Evaluator with 10,000 expressions
ITestCase ITestExecutioner IExpectedDataAdapter IPublisher<R> ILogger<L> IInputAdapter <R> execute(<D>) execute() <D> getInput(index); IntgetCount(); <R> getExpected(index); IntgetCount(); Init(); collect(); publish() log();
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();
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();
More Theory of Spring Core • Constructor Dependency Injection • Setter Dependency Injection • Auto Wiring • Bean Scope • Lazy Init • Initiating Spring Framework
Constructor Injection <!-- IInputAdapter, IExpectedDataAdapter Implementation --> <bean id="testDataAdapter" class="com.design.di.production.TestDataAdapter"> <constructor-arg type="java.lang.String" value="testdata.csv"/> </bean>
Setter Injection <!-- Executioner Implementation --> <bean id="executioner" class="com.design.di.production.ActualExecutioner"> <property name="resultPublisher"> <ref bean="csvPublisher"/> </property> …. </bean>
Auto Wiring Requirement - All my beans require a logger. Q – Do I explicitly put logger ref in all beans? A – No, Use Auto Wiring
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>
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>
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"/>
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
Scope of this talk • Understanding Rapid App Development • Demo Spring Roo • Excite you guys to take a session on Roo
Rapid Application Development Generated Code Adapts to new inputs Configuration Burden Commands for Convention No Lock In Extensible
Typical Application Flow Define Entities Security CRUD DAOs Application Logic DAO Unit Test cases Integration Tests Web Controller Deploy Controller Test Cases
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
Q & A? Contact us at rohitsghatol@gmail.com