Store Of Core Spring
                                  Mak Bhatamrekar
                   http://github.com/makrand-bkar

                                             AJCP




http://meetup.com/my-ajcp
Atlanta Java Concept Pros
Agenda

•   The Problem
•   Solution With No Spring and Challenges
•   Magic Of Spring Core/ DI
•   More on XML Config & Co`ncepts
•   Must Know Key Concepts
•   Whats new Spring 3
•   Recap
Dependencies




               
TATA NANO
Issues
Multiple Programmers              Practical Aspects
• Create Dummy Classes            ? Different Test and
   – Method Names e.g getType()   Production Configurations
     in engine
• Code and Compile                ?Reduced Test Cycles
   – Add image here

                                  ?Cluttered Business Logic
Spring Framework – The Hero
              Important Dates
              • Spring 1.0 - 2004
              • Spring 1.2.6 – Won Awards
              • Spring 2.0 – Oct 2006
              • Spring 2.5 – Nov 2007
              • Spring 3.0 – Dec 2009
              • Spring 3.1 – Dec 2011
              • Spring 3.2.1 – Jan 2013
              • Spring 4.0 – End of Year
Spring Framework
Josh long-a-walking-tour-of-spring-3-1-pdf-d421509802 -
Spring Projects
•   Spring Security
•   Spring Integration
•   Spring Batch
•   Spring Data
•   Spring Web Services
•   Spring Web
•   Spring Social
•   Spring Android
•   More..
DriverMain
Dependency Injection is a form of Inversion Of
Control.
Also know as the Hollywood Principle
   “Don’t call us, we’ll call you! “
DI Types
• XML Based
• Annotation Based
  – Bypass some of the XML Configurations with XML
    Support.
• Java Based
<bean id="car" class="com.ajcp.withspring.v1.testimpl.Car">
<!-- setter Injection example -->
<constructor-arg ref="tireList" />
<bean id="engine" class="com.ajcp.withspring.v1.testimpl.Engine">
<constructor-arg ref="engine" />
<property name="type" value="V4"></property>
</bean>
</bean>
Important Configs
•    <context:annotation-config />
•   <context:component-scan>
•   p: -- namespace for setter injections
•   c: -- namespace for getter injects
•   util: -- useful utilties for DI
•   aop – aop support
•   tx – transaction support
At it’s core – Spring is a framework for wiring up
your entire application
@Autowired
• byName - by property name
• byType - by property type
• Constructor – Similar to byType but applies to
  constructor args
• Autodetect – first autowires by constructor, if
  that fails autowires byType.
<context:annotation-config />
                     <context:component-scan base-
                     package="com.ajcp.withspring.v2annotation.testimpl"
                     />
                     <bean id="brand"
                     class="com.ajcp.withspring.v2annotation.testimpl.Bran
                     d"/>



<!– Autowire byType -->
<bean id="tire1"
class="com.ajcp.withspring.v2annotation.testimpl.TireImpl"
 autowire="byType"></bean>




   <!– Autowire constructor-->
   <bean id="carService"
   class="com.ajcp.withspring.v2annotation.testimpl.CarImpl"
   autowire="constructor">
Spring DI Annotations
•   @Required
•   @Autowired
•   @Qualifier
•   @Resource – JSR Annotation –
    – Combines @Autowired and @Qualifier
• @Component
• @Service
• @Repository
@Autowired // beans are autowired by Type
private EngineService engineService;
@Autowired
@Qualifier("tire1")
private TireService tireService;
public static void main(String[] args) {
                                         ApplicationContext context =
                                         new
                                         ClassPathXmlApplicationContext("BeansWit
                                         Annotation.xml");
@Bean                                    Driver driver = (Driver)
 @Scope("prototype")                     context.getBean("driver");
 public EngineService engineService(){   driver.createCarAndDrive();
   EngineService e = new EngineImpl();
   e.setType(EngineImpl.V6_ENGINE);
   return e;
 }




                             Java Based Config
Bean Scopes
•   Singleton (default)
•   Prototype
•   Request
•   Session
•   Global session
Steps To Execute SourceCode
1. Download from github, Zip option is also
   there
2. cd SpringCoreCarSample
3. mvn compile eclipse:eclipse
4. Open Eclipse
5. Select File ->Import -> Existing Projects Into..
6. Run the Main classes as Application from
   Eclipse
Reference Links
Meetup.com / Atlanta Spring Users Group

•https://github.com/makrand-bkar/SpringCoreCarSample
•http://www.tutorialspoint.com/spring/
•http://www.mkyong.com/spring/
•http://www.springsource.org/tutorials
Store Of Core Spring
                                 Mak Bhatamrekar
           github :http://github.com/makrand-bkar
                                  twitter : mak-bkar
                         url : www.careerinjava.com



http://meetup.com/my-ajcp
Atlanta Java Concept Pros

Story ofcorespring infodeck

  • 1.
    Store Of CoreSpring Mak Bhatamrekar http://github.com/makrand-bkar AJCP http://meetup.com/my-ajcp Atlanta Java Concept Pros
  • 2.
    Agenda • The Problem • Solution With No Spring and Challenges • Magic Of Spring Core/ DI • More on XML Config & Co`ncepts • Must Know Key Concepts • Whats new Spring 3 • Recap
  • 3.
  • 4.
  • 6.
    Issues Multiple Programmers Practical Aspects • Create Dummy Classes ? Different Test and – Method Names e.g getType() Production Configurations in engine • Code and Compile ?Reduced Test Cycles – Add image here ?Cluttered Business Logic
  • 8.
    Spring Framework –The Hero Important Dates • Spring 1.0 - 2004 • Spring 1.2.6 – Won Awards • Spring 2.0 – Oct 2006 • Spring 2.5 – Nov 2007 • Spring 3.0 – Dec 2009 • Spring 3.1 – Dec 2011 • Spring 3.2.1 – Jan 2013 • Spring 4.0 – End of Year
  • 9.
  • 10.
    Spring Projects • Spring Security • Spring Integration • Spring Batch • Spring Data • Spring Web Services • Spring Web • Spring Social • Spring Android • More..
  • 11.
  • 12.
    Dependency Injection isa form of Inversion Of Control. Also know as the Hollywood Principle “Don’t call us, we’ll call you! “
  • 13.
    DI Types • XMLBased • Annotation Based – Bypass some of the XML Configurations with XML Support. • Java Based
  • 14.
    <bean id="car" class="com.ajcp.withspring.v1.testimpl.Car"> <!--setter Injection example --> <constructor-arg ref="tireList" /> <bean id="engine" class="com.ajcp.withspring.v1.testimpl.Engine"> <constructor-arg ref="engine" /> <property name="type" value="V4"></property> </bean> </bean>
  • 15.
    Important Configs • <context:annotation-config /> • <context:component-scan> • p: -- namespace for setter injections • c: -- namespace for getter injects • util: -- useful utilties for DI • aop – aop support • tx – transaction support
  • 16.
    At it’s core– Spring is a framework for wiring up your entire application
  • 17.
    @Autowired • byName -by property name • byType - by property type • Constructor – Similar to byType but applies to constructor args • Autodetect – first autowires by constructor, if that fails autowires byType.
  • 18.
    <context:annotation-config /> <context:component-scan base- package="com.ajcp.withspring.v2annotation.testimpl" /> <bean id="brand" class="com.ajcp.withspring.v2annotation.testimpl.Bran d"/> <!– Autowire byType --> <bean id="tire1" class="com.ajcp.withspring.v2annotation.testimpl.TireImpl" autowire="byType"></bean> <!– Autowire constructor--> <bean id="carService" class="com.ajcp.withspring.v2annotation.testimpl.CarImpl" autowire="constructor">
  • 19.
    Spring DI Annotations • @Required • @Autowired • @Qualifier • @Resource – JSR Annotation – – Combines @Autowired and @Qualifier • @Component • @Service • @Repository
  • 20.
    @Autowired // beansare autowired by Type private EngineService engineService; @Autowired @Qualifier("tire1") private TireService tireService;
  • 21.
    public static voidmain(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("BeansWit Annotation.xml"); @Bean Driver driver = (Driver) @Scope("prototype") context.getBean("driver"); public EngineService engineService(){ driver.createCarAndDrive(); EngineService e = new EngineImpl(); e.setType(EngineImpl.V6_ENGINE); return e; } Java Based Config
  • 22.
    Bean Scopes • Singleton (default) • Prototype • Request • Session • Global session
  • 23.
    Steps To ExecuteSourceCode 1. Download from github, Zip option is also there 2. cd SpringCoreCarSample 3. mvn compile eclipse:eclipse 4. Open Eclipse 5. Select File ->Import -> Existing Projects Into.. 6. Run the Main classes as Application from Eclipse
  • 24.
    Reference Links Meetup.com /Atlanta Spring Users Group •https://github.com/makrand-bkar/SpringCoreCarSample •http://www.tutorialspoint.com/spring/ •http://www.mkyong.com/spring/ •http://www.springsource.org/tutorials
  • 25.
    Store Of CoreSpring Mak Bhatamrekar github :http://github.com/makrand-bkar twitter : mak-bkar url : www.careerinjava.com http://meetup.com/my-ajcp Atlanta Java Concept Pros

Editor's Notes

  • #3 Whats the Problem we are trying to solve
  • #5 TATA NANO has Engine on the Back when the person sits -- TODO Add the Trunk Image
  • #10 Spring DI which allows ot inject dependencies, so your code base is made only of interface and does not know about implementations Spring AOP is the declarative aspect which allows to add a nature to a class, like Translcation, logging Portal Service Abstracts + Good Documentation