Story ofcorespring infodeck

25
Store Of Core Spring Mak Bhatamrekar http://github.com/makrand-bkar AJCP http://meetup.com/my-ajcp Atlanta Java Concept Pros

Transcript of Story ofcorespring infodeck

Page 1: Story ofcorespring infodeck

Store Of Core Spring

Mak Bhatamrekar

http://github.com/makrand-bkar

AJCP

http://meetup.com/my-ajcpAtlanta Java Concept Pros

Page 2: Story ofcorespring infodeck

• 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

Agenda

Page 3: Story ofcorespring infodeck

Dependencies

Page 4: Story ofcorespring infodeck

TATA NANO

Page 5: Story ofcorespring infodeck
Page 6: Story ofcorespring infodeck

Issues

Multiple Programmers

• Create Dummy Classes– Method Names e.g getType()

in engine

• Code and Compile– Add image here

Practical Aspects

? Different Test and Production Configurations

?Reduced Test Cycles

?Cluttered Business Logic

Page 7: Story ofcorespring infodeck
Page 8: Story ofcorespring infodeck

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

Page 9: Story ofcorespring infodeck

Josh long-a-walking-tour-of-spring-3-1-pdf-d421509802 -

Spring Framework

Page 10: Story ofcorespring infodeck

Spring Projects

• Spring Security• Spring Integration• Spring Batch• Spring Data• Spring Web Services• Spring Web• Spring Social• Spring Android• More..

Page 11: Story ofcorespring infodeck

DriverMain

Page 12: Story ofcorespring infodeck

Dependency Injection is a form of Inversion Of Control.

Also know as the Hollywood Principle

“Don’t call us, we’ll call you! “

Page 13: Story ofcorespring infodeck

DI Types

• XML Based• Annotation Based– Bypass some of the XML Configurations with XML

Support.

• Java Based

Page 14: Story ofcorespring infodeck

<!-- setter Injection example --><bean id="engine" class="com.ajcp.withspring.v1.testimpl.Engine"><property name="type" value="V4"></property></bean>

<bean id="car" class="com.ajcp.withspring.v1.testimpl.Car"><constructor-arg ref="tireList" /><constructor-arg ref="engine" /></bean>

Page 15: Story ofcorespring infodeck

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

Page 16: Story ofcorespring infodeck

At it’s core – Spring is a framework for wiring up your entire application

Page 17: Story ofcorespring infodeck

@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.

Page 18: Story ofcorespring infodeck

<!– 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"></bean>

<context:annotation-config /><context:component-scan base-package="com.ajcp.withspring.v2annotation.testimpl" /><bean id="brand" class="com.ajcp.withspring.v2annotation.testimpl.Brand"/>

Page 19: Story ofcorespring infodeck

Spring DI Annotations

• @Required• @Autowired • @Qualifier• @Resource – JSR Annotation – – Combines @Autowired and @Qualifier

• @Component• @Service• @Repository

Page 20: Story ofcorespring infodeck

@Autowired // beans are autowired by Typeprivate EngineService engineService;@Autowired@Qualifier("tire1")private TireService tireService;

Page 21: Story ofcorespring infodeck

@Bean @Scope("prototype") public EngineService engineService(){ EngineService e = new EngineImpl(); e.setType(EngineImpl.V6_ENGINE); return e; }

Java Based Config

public static void main(String[] args) {ApplicationContext context =new ClassPathXmlApplicationContext("BeansWithAnnotation.xml");Driver driver = (Driver) context.getBean("driver");driver.createCarAndDrive();

Page 22: Story ofcorespring infodeck

Bean Scopes

• Singleton (default)• Prototype• Request• Session• Global session

Page 23: Story ofcorespring infodeck

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

Page 24: Story ofcorespring infodeck

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

Page 25: Story ofcorespring infodeck

Store Of Core Spring

Mak Bhatamrekar

github :http://github.com/makrand-bkar

twitter : mak-bkar

url : www.careerinjava.com

http://meetup.com/my-ajcpAtlanta Java Concept Pros