Spring 3 - An Introduction
-
Upload
thorsten-kamann -
Category
Technology
-
view
2.535 -
download
4
description
Transcript of Spring 3 - An Introduction
![Page 1: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/1.jpg)
![Page 2: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/2.jpg)
Spezialist für modellbasierte Entwicklungsverfahren
Gründung im Jahr 2003
Niederlassungen in Deutschland, Frankreich, Schweiz und Kanada
140 Mitarbeiter
Strategisches Mitglied der Eclipse Foundation
Intensive Verzahnung im Bereich der Forschung
Mitglied von ARTEMISIA
Embedded Software Development
Enterprise Application Development
![Page 3: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/3.jpg)
![Page 4: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/4.jpg)
Von und mit Thorsten Kamann
22.02.2010
![Page 5: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/5.jpg)
![Page 6: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/6.jpg)
![Page 7: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/7.jpg)
jUnit 3 Klassen
Commons Attributes
Struts 1.x Support
-
![Page 8: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/8.jpg)
100% API
95% Extension
Points
Spring 3
![Page 9: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/9.jpg)
Modules OSGi
Maven Enterprise Repository
![Page 10: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/10.jpg)
#{...} @Value
XML ExpressionParser
Expression Language
![Page 11: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/11.jpg)
<bean class=“MyDatabase"> !!<property name="databaseName" !! value="#{systemProperties.databaseName}"/> !!<property name="keyGenerator" !! value="#{strategyBean.databaseKeyGenerator}"/> !
</bean> !
![Page 12: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/12.jpg)
@Repository !public class MyDatabase { !
!@Value("#{systemProperties.databaseName}") !!public void setDatabaseName(String dbName) {…} !
!@Value("#{strategyBean.databaseKeyGenerator}") !!public void setKeyGenerator(KeyGenerator kg) {…} !
} !
![Page 13: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/13.jpg)
Database db = new MyDataBase(„myDb“, „uid“, „pwd“);!
ExpressionParser parser = new SpelExpressionParser();!Expression exp = parser.parseExpression("name");!
EvaluationContext context = new ! ! !! ! ! !StandardEvaluationContext();!
context.setRootObject(db);!
String name = (String) exp.getValue(context);!
![Page 14: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/14.jpg)
Database db = new MyDataBase(„myDb“, „uid“, „pwd“);!
ExpressionParser parser = new SpelExpressionParser();!Expression exp = parser.parseExpression("name");!
String name = (String) exp.getValue(db);!
![Page 15: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/15.jpg)
@Configuration @Bean @DependsOn
@Primary @Lazy @Import
@ImportResource @Value
![Page 16: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/16.jpg)
@Configuration!public class AppConfig {! !@Value("#{jdbcProperties.url}") !
!private String jdbcUrl;! !!
!@Value("#{jdbcProperties.username}") !!private String username;!
!@Value("#{jdbcProperties.password}") !!private String password;!
}!
![Page 17: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/17.jpg)
@Configuration!public class AppConfig {! !@Bean! !public FooService fooService() {! return new FooServiceImpl(fooRepository());! !}!
!@Bean! !public DataSource dataSource() { ! return new DriverManagerDataSource(!
! !jdbcUrl, username, password);! !}!
}!
![Page 18: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/18.jpg)
@Configuration!public class AppConfig {! !@Bean! !public FooRepository fooRepository() {! return new HibernateFooRepository! ! !
! ! ! ! !(sessionFactory());! }!
@Bean! public SessionFactory sessionFactory() {!
!...! }!}!
![Page 19: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/19.jpg)
<context:component-scan !!base-package="org.example.config"/>
<util:properties id="jdbcProperties" ! !location="classpath:jdbc.properties"/>!
![Page 20: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/20.jpg)
public static void main(String[] args) {! ApplicationContext ctx = !
!new AnnotationConfigApplicationContext(!! ! ! ! ! !AppConfig.class);!
FooService fooService = ctx.getBean(!! ! ! ! ! !FooService.class);!
fooService.doStuff();!}!
![Page 21: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/21.jpg)
Marshalling
JAXB Castor
Unmarshalling
JiBX Xstream XMLBeans
![Page 22: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/22.jpg)
<oxm:jaxb2-marshaller !!id="marshaller" !!contextPath=“my.packages.schema"/>!
<oxm:jaxb2-marshaller id="marshaller">! <oxm:class-to-be-bound name=“Customer"/>! <oxm:class-to-be-bound name=„Address"/>! ...!</oxm:jaxb2-marshaller>!
![Page 23: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/23.jpg)
<beans>! <bean id="castorMarshaller" !
!class="org.springframework.oxm.castor.CastorMarshaller" >! <property name="mappingLocation"
! !value="classpath:mapping.xml" />! </bean>!</beans>
![Page 24: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/24.jpg)
<oxm:xmlbeans-marshaller !!id="marshaller“!!options=„XMLOptionsFactoryBean“/>!
![Page 25: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/25.jpg)
<oxm:jibx-marshaller !!id="marshaller" !!target-class=“mypackage.Customer"/>!
![Page 26: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/26.jpg)
<beans>!
<bean id="xstreamMarshaller" !class="org.springframework.oxm.xstream.XStreamMarshaller">!
<property name="aliases">! <props>! <prop key=“Customer">mypackage.Customer</prop>! </props>! !</property>! </bean>! ...!
</beans>!
![Page 27: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/27.jpg)
Spring MVC
@Controller @RequestMapping @PathVariable
![Page 28: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/28.jpg)
@Controller
The C of MVC
<context:component-scan/>
Mapping to an URI (optional)
![Page 29: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/29.jpg)
@RequestMapping
Mapping a Controller or Methods to an URI
URI-Pattern
Mapping to a HTTP-Method
Works with @PathVariable
![Page 30: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/30.jpg)
@Controller!@RequestMapping(„/customer“)!public class CustomerController{!
!@RequestMapping(method=RequestMethod.GET)!!public List<Customer> list(){!! !return customerList;!!}!
}!
![Page 31: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/31.jpg)
@Controller!@RequestMapping(„/customer“)!public class CustomerController{!
!@RequestMapping(value=„/list“,!! ! ! ! !method=RequestMethod.GET)!!public List<Customer> list(){!! !return customerList;!!}!
}!
![Page 32: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/32.jpg)
@Controller!@RequestMapping(„/customer“)!public class CustomerController{!
!@RequestMapping(value=„/show/{customerId}“,!! ! ! ! !method=RequestMethod.GET)!!public Customer show(!! @PathVariable(„customerId“) long customerId){!! !return customer;!!}!
}!
![Page 33: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/33.jpg)
@Controller!@RequestMapping(„/customer“)!public class CustomerController{!
!@RequestMapping(!! !value=„/show/{customerId}/edit/{addressId}“,!! ! ! ! !method=RequestMethod.GET)!!public String editAddressDetails(!! @PathVariable(„customerId“) long customerId,!! @PathVariable(„addressId“) long addressId){!! !return „redirect:...“;!!}!
}!
![Page 34: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/34.jpg)
RestTemplate
Delete Get Head Options Post Put
![Page 35: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/35.jpg)
public void displayHeaderInfo(! @RequestHeader("Accept-Encoding") String encoding,! @RequestHeader("Keep-Alive") long keepAlive) {!
!...!
}!
Host localhost:8080!Accept text/html, application/xml;q=0.9!Accept-Language fr,en-gb;q=0.7,en;q=0.3!Accept-Encoding gzip,deflate!Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7!Keep-Alive 300!
![Page 36: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/36.jpg)
public class VistorForm(!!@NotNull!
!@Size(max=40)!!private String name;!
!@Min(18)!!private int age;!
}!
<bean id="validator" !!class=“...LocalValidatorFactoryBean" />!
JSR-303
![Page 37: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/37.jpg)
HSQL H2 Derby ...
![Page 38: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/38.jpg)
<jdbc:embedded-database id="dataSource">! <jdbc:script location="classpath:schema.sql"/>! <jdbc:script location="classpath:test-data.sql"/>!</jdbc:embedded-database>!
EmbeddedDatabaseBuilder builder = new ! !! ! ! !EmbeddedDatabaseBuilder();!
EmbeddedDatabase db = builder.setType(H2)!! ! ! !.addScript(“schema.sql")!! ! ! !.addScript(„test-data.sql")!! ! ! !.build();!
//Do somethings: db extends DataSource!db.shutdown();!
![Page 39: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/39.jpg)
public class DataBaseTest {! private EmbeddedDatabase db;!
@Before! public void setUp() {!
!db = new EmbeddedDatabaseBuilder()!! !.addDefaultScripts().build();! !!
}!
@Test! public void testDataAccess() {! JdbcTemplate template = new JdbcTemplate(db);! template.query(...);! }!
@After! public void tearDown() {! db.shutdown();! }!}!
![Page 40: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/40.jpg)
@Async (out of EJB 3.1)
JSR-303
JSF 2.0
JPA 2
![Page 41: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/41.jpg)
![Page 42: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/42.jpg)
Spri
ng A
pplic
atio
n T
ools
• Spring project, bean and XML file wizards
• Graphical Spring configuration editor
• Spring 3.0 support including @Configuration and @Bean styles
• Spring Web Flow and Spring Batch visual development tools
• Spring Roo project wizard and development shell
• Spring Application blue prints and best practice validation
OSG
i • OSGi bundle overview and visual dependency graph
• Classpath management based on OSGi meta data
• Automatic generation of manifest dependency meta data
• SpringSource Enterprise Bundle Repository browser
• Manifest file validation and best practice recommendations
Fle
xibl
e D
eplo
ymen
ts
• Support for all the most common Java EE application servers
• Advanced support for SpringSource dm Server
• Advanced support for SpringSource tc Server
• Cloud Foundry targeting for dm Server and tc Server
• VMware Lab Manager and Workstation integration and deployment
![Page 43: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/43.jpg)
![Page 44: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/44.jpg)
![Page 45: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/45.jpg)
![Page 46: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/46.jpg)
![Page 47: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/47.jpg)
![Page 48: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/48.jpg)
Grails for Java
Spring Best Practices
AOP-driven
Test-driven Nice Console
![Page 49: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/49.jpg)
Command Line Shell
@Roo* Annotations
(Source-Level)
AspectJ Intertype
Declarations Metadata RoundTrip
![Page 50: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/50.jpg)
![Page 51: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/51.jpg)
![Page 52: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/52.jpg)
![Page 53: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/53.jpg)
roo> project --topLevelPackage com.tenminutes roo> persistence setup --provider HIBERNATE
--database HYPERSONIC_IN_MEMORY roo> entity --class ~.Timer --testAutomatically roo> field string --fieldName message --notNull roo> controller all --package ~.web roo> selenium test --controller ~.web.TimerController roo> perform tests roo> perform package roo> perform eclipse roo> quit $ mvn tomcat:run
![Page 54: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/54.jpg)
![Page 55: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/55.jpg)
![Page 56: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/56.jpg)
Roo for Groovy
Best Practices
Groovy-driven
Test-driven
Nice Console
![Page 57: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/57.jpg)
Rapid Dynamic Robust
Have your next Web 2.0 project done in weeks instead of months. Grails delivers a new age of Java web application productivity.
Get instant feedback, See instant results. Grails is the premier dynamic language web framework for the JVM.
Powered by Spring, Grails out performs the competition. Dynamic, agile web development without compromises.
![Page 58: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/58.jpg)
Project Wizard Support
different Grails Versions
Grails Project Converter
Grails Tooling Full Groovy Support
Grails Command
Prompt
![Page 59: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/59.jpg)
![Page 60: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/60.jpg)
CTRL+ALT+G (or CMD+ALT+G on Macs)
![Page 61: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/61.jpg)
![Page 62: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/62.jpg)
>grails create-app tenminutes-grails!<grails create-domain-class tenminutes.domain.Timer!
Timer.groovy:!class Timer {!
!String message! !static constraints = {!
! !message(nullable: false)! !}!}!
>grails create-controller tenminutes.web.TimerController!
TimerController.groovy:!class TimerControllerController {!
!def scaffold = Timer!}!
>grails run-app!
![Page 63: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/63.jpg)
![Page 64: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/64.jpg)
• http://www.springframework.org/ • http://www.springsource.com/ Spring
• http://www.grails.org/ • http://groovy.codehaus.org/
Grails & Groovy
• http://www.thorsten-kamann.de • http://www.itemis.de Extras
![Page 65: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/65.jpg)
![Page 66: Spring 3 - An Introduction](https://reader033.fdocument.pub/reader033/viewer/2022042714/54b3bf374a7959d10e8b4573/html5/thumbnails/66.jpg)
Erfolg durch Agilität: Scrum-Kompakt mit Joseph Pelrine –
14:00 bis 18:00 25. Februar 2010
Joseph Pelrine, Jena, Veranstalter: itemis AG
Von »Exzellenten Wissensorganisationen« lernen
– 13:00 bis 18:30 25. Februar 2010
Lise-Meitner-Allee 6, 44801 Bochum, Veranstalter: ck 2
Embedded World 2010 – Halle 10 – Stand 529
02.-04. März 2010 Nürnberg - Messezentrum 1
Hands On Model-Based Development with Eclipse –
09:30 bis 16:30 04. März 2010
Axel Terfloth, Andreas Unger, embeddedworld Nürnberg
Zukunft der Wissensarbeit. Best Practice Sharing auf der CeBIT 2010 – 10:00 bis 13:00
04. März 2010 Exzellente Wissensorganisation,
Hannover, Veranstalter: ck 2, kostenlos