Developing Agile Java Applications using Spring tools

19
Developing Java Applications in Agile way using SpringSource Tool Suite (STS) 2.3.2, Maven, Spring tc server Presented by : Sathish Chittibabu Date : May 11 th 2010 Event : Solstice Consultants Round table discussion

description

Developing Agile Java Applications using Spring tools

Transcript of Developing Agile Java Applications using Spring tools

Page 1: Developing Agile Java Applications using Spring tools

Developing Java Applications in Agile way using SpringSource Tool Suite (STS) 2.3.2, Maven,

Spring tc server

Presented by : Sathish ChittibabuDate : May 11th 2010Event : Solstice Consultants Round table

discussion

Page 2: Developing Agile Java Applications using Spring tools

Agenda

2/19

• Spring Framework (Introduction)• Spring 3.0 – What’s new ? (if needed) • SpringSource Tool Suite (STS) 2.3.2• Spring tcServer• Maven• Quick example • So what’s Agile here ?

Page 3: Developing Agile Java Applications using Spring tools

No Spring Allergy !!!

3/19

Page 4: Developing Agile Java Applications using Spring tools

Spring Framework

• Open source framework for Java development ( Spring Core, Spring MVC, Spring JDBC, Web Services etc.,)• Lightweight, non-invasive container• Dependency Injection or Inversion of Controller• Assemble complex system from loosely coupled POJOs• Reusable business and data access components not

tied to J2EE services. • Spring managed applications can run in any J2EE

environment, as standalone apps, test environments• Lean Software Movement

4/19

Page 5: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ?

• Java 5+ support• Spring Expression Language• REST Support• Portlet 2.0• Declarative model validation• Early support for Java EE6

5/19

Page 6: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • Java 5+ support • Generics – Beanfactory returns typed bean instancesT getBean(String name, Class<T> type) Map<String, T> getBeansOfType(Class<T>, type)

• TaskExecutor interface extends from java.util.concurrent.Executor (supports standard callables with Futures)• Configuration 3 types• XML Based (applicationContext.xml)• Annotations in the beans (@ Components)• Configuration classes (Spring Java Config Project)

6/19

Page 7: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • Spring Java Config Project • Java configuration class instead of XML Configuration• Everything in Java – stronger type checking• Dependencies confined to one place. No additional

annotations inside the app code• Every method returns a spring managed bean@Bean @Primary @Lazypublic DemoService demoService(){

DemoServiceImpl service = new DemoServiceImpl();service.setDataSource(…);return service;

}

7/19

Page 8: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • Meta Annotations• Making custom annotations (your own stereotypes)

more powerful• App code doesn’t depend on Spring Annotations

instead uses Java Annotations@Service@Scope ("request")@Transactional(rollbackFor=Exception.class)@Retention(RetentionPolicy.RUNTIME)public @interface MyService{}

@MyServicepublic class DemoService{…}

8/19

Page 9: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • Spring Expression Language• Similar to managed beans in JSF Expressions• Implicit attributes to be exposed by default (e.g.,

systemProperties, systemEnviroment)• Implicit web specific attributes are also available (e.g.,

contextParameters, contextAttributes, request, session)#{systemProperties.databaseName}#{myBean.myProperty}

9/19

Page 10: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • REST in Spring MVC

• @PathVariable introduced – URI templates

@Controller@RequestMapping("/hotels/{hotel}") --- optionalpublic class HotelsController{

@RequestMapping -- matches /hotels/42

public void handleHotel(@PathVariable("hotel") String hotel) {//...

}

@RequestMapping("bookings/{booking}") -- matches /hotels/42/bookings/21

public void handleBooking(@PathVariable("hotel") String hotel, @PathVariable int booking){

// ...}

}10/19

Page 11: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • New Views added• application/xml – MarshallingView• application/atom+xml – AbstractAtomFeedView• aplication/rss+xml – AbstractRssFeedView• application/json –

MappingJacksonJsonView• Parameter Annotations• @RequestHeader, @RequestBody, @ResponseBody,

@CookieValue

• On the Client Side• RestTemplate (very similar to jdbcTemplate)

11/19

Page 12: Developing Agile Java Applications using Spring tools

Spring 3.0 – What’s new ? • Declarative Validation• JSR 303 – “Bean Validation” through annotation• Validation in any layer

public class DemoBean {@NotNull@Pastprivate Date someDate;

}

12/19

Page 13: Developing Agile Java Applications using Spring tools

SpringSource Tool Suite (STS) 2.3.2

• Eclipse-powered Java Integrated development environment (IDE) for building spring-powered enterprise applications• Includes tools for all of the latest Enterprise Java and

Spring based technologies• Supports application targeting local, virtual and cloud

based servers• In built support for SpringSource dmServer and

SpringSource tcServer• Also available as Eclipse plugin

13/19

Page 14: Developing Agile Java Applications using Spring tools

Spring tcServer• Enterprise version of Apache Tomcat• Spring and Apache Tomcat – KISSing cousins• Lightweight App Server suited for usage in modern virtual

or Cloud environments• Small foot print, lean approach requires significantly less

computing resources• Available in Spring edition, Standard edition and

Developer edition• Developer edition is integrated with STS• Spring insight – analytical and advanced diagnostic tool

for real time insight into performance (metrics) and behavior of Spring applications

14/19

Page 15: Developing Agile Java Applications using Spring tools

Maven• Project Management and comprehension tool to manage

– Builds, Documentation, Reporting, Dependencies, – SCMs, Releases, Distribution

• Ant is procedural while Maven is Object Oriented• Employs standard conventions and practices to accelerate

development cycle• Concept of Central Repository – share 3rd party and open source

libraries across projects (intranet as well internet)• Continuous Integration – automated build, release, tests etc.,• In words of Jason van Zyl

– "the intent of Maven is to make intra-project development highly manageable in the hopes of providing more time for cross-project development. You might call it cross-project pollination or the sharing of project development knowledge; this is what Maven attempts to encourage".

15/19

Page 16: Developing Agile Java Applications using Spring tools

Maven – Pom.xmlPOM (Project Object Model) – XML representation of maven project

Declarative manifestation of “who” , “what” and “where”, while the build lifecycle is the “when” and “how”

Maven solves Dependency Management issues “jarmageddon” and “jar Hell” thru common local repository from which to link projects correctly

16/19

Page 17: Developing Agile Java Applications using Spring tools

Maven- Standard Layout for ProjectsJava sources go under ${basedir}/src/main/java

Web stuff go under ${basedir}/src/main/webapp

Test sources go under ${basedir}/src/test/java

Compiled classes go under ${basedir}/target/classes

where ${basedir} represents the directory containing pom.xml

Maven local repository – ~/.m2/repository

17/19

Page 18: Developing Agile Java Applications using Spring tools

So What’s Agile here ?

• Don’t have to worry about build infrastructure – boiler plate

• Don’t have to scratch your head on the different version of libraries

• Don’t have to spend time on App server setup on your dev environment

• Can develop “Runtime Environment Agnostic” Java code• Development is quick - Hot deployment on tcServer• Develop lean software – easy to support & maintain • And now you can actually concentrate on building

application code

18/19

Page 19: Developing Agile Java Applications using Spring tools

Q & A

19/19