Story ofcorespring infodeck

Post on 06-Jul-2015

243 views 0 download

Transcript of Story ofcorespring infodeck

Store Of Core Spring

Mak Bhatamrekar

http://github.com/makrand-bkar

AJCP

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

• 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

Dependencies

TATA NANO

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

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

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

Spring Framework

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

<!-- 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>

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.

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

Spring DI Annotations

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

• @Component• @Service• @Repository

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

@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();

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-ajcpAtlanta Java Concept Pros