Your SlideShare is downloading. ×
Spring 3 - Der dritte Frühling
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Spring 3 - Der dritte Frühling

1,796
views

Published on

»Spring 3« ist da. Vieles ist geblieben, manches verschwunden, manches neu. Spring 3 verspricht eine verbesserte und dynamischere Konfiguration, einen leistungsfähigen und mächtigen REST-Support und …

»Spring 3« ist da. Vieles ist geblieben, manches verschwunden, manches neu. Spring 3 verspricht eine verbesserte und dynamischere Konfiguration, einen leistungsfähigen und mächtigen REST-Support und viele kleine Verbesserungen. Parallel zu dem Spring 3-Release wurden auch andere Tools und Projekte aktualisiert, auf die wir ebenfalls einen Blick werfen wollen:

* Wichtige Änderungen
* Java Configuration
* Spring Expression Language
* Spring MVC und Rest
* Embedded Database
* SpringSource Toolsuite
* Spring Roo
* Grails

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,796
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Thorsten Kamann · itemis AG · 15.03.2010
  • 2. What‘s new, what‘s old? Configuration OX/Mapper REST-Support MVC, Embedded Database, EE6 SpringSource Toolsuite Spring Roo Grails
  • 3. - jUnit 3 Klassen Commons Attributes Struts 1.x Support
  • 4. 100% API Spring 3 95% Extension Points
  • 5. Modules OSGi Enterprise Maven Repository
  • 6. #{...} Expression Language Java Config
  • 7. #{...} @Value Expression Language XML ExpressionParser
  • 8. <bean class=“MyDatabase"> ! !<property name="databaseName" ! ! value="#{systemProperties.databaseName}"/> ! !<property name="keyGenerator" ! ! value="#{strategyBean.databaseKeyGenerator}"/> ! </bean> !
  • 9. @Repository ! public class MyDatabase { ! !@Value("#{systemProperties.databaseName}") ! !public void setDatabaseName(String dbName) {…} ! !@Value("#{strategyBean.databaseKeyGenerator}") ! !public void setKeyGenerator(KeyGenerator kg) {…} ! } !
  • 10. 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);!
  • 11. Database db = new MyDataBase(„myDb“, „uid“, „pwd“);! ExpressionParser parser = new SpelExpressionParser();! Expression exp = parser.parseExpression("name");! String name = (String) exp.getValue(db);!
  • 12. @Configuration @Bean @DependsOn @Primary @Lazy @Import @ImportResource @Value
  • 13. @Configuration! public class AppConfig {! @Value("#{jdbcProperties.url}") ! !private String jdbcUrl;! !! !@Value("#{jdbcProperties.username}") ! !private String username;! !@Value("#{jdbcProperties.password}") ! !private String password;! }!
  • 14. @Configuration! public class AppConfig {! @Bean! !public FooService fooService() {! ! !return new FooServiceImpl(fooRepository());! }! !@Bean! public DataSource dataSource() { ! !return new DriverManagerDataSource(! ! ! !jdbcUrl, username, password);! }! }!
  • 15. @Configuration! public class AppConfig {! @Bean! !public FooRepository fooRepository() {! ! !return new HibernateFooRepository ! ! !
 ! ! !(sessionFactory());! }! @Bean! public SessionFactory sessionFactory() {! ! !...! }! }!
  • 16. <context:component-scan ! !base-package="org.example.config"/>
 <util:properties id="jdbcProperties" 
 ! !location="classpath:jdbc.properties"/>!
  • 17. public static void main(String[] args) {! ApplicationContext ctx = ! ! ! !new AnnotationConfigApplicationContext(! ! ! ! ! ! ! ! ! ! ! ! !AppConfig.class);! FooService fooService = ctx.getBean(! ! ! ! ! ! ! ! ! ! ! ! !FooService.class);! fooService.doStuff();! }!
  • 18. <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>!
  • 19. <beans>! <bean id="castorMarshaller" ! !class="org.springframework.oxm.castor.CastorMarshaller" >! <property name="mappingLocation" 
 ! !value="classpath:mapping.xml" />! </bean>! </beans>

  • 20. <oxm:xmlbeans-marshaller ! !id="marshaller“! !options=„XMLOptionsFactoryBean“/>!
  • 21. <oxm:jibx-marshaller ! !id="marshaller" ! !target-class=“mypackage.Customer"/>!
  • 22. <beans>! <bean id="xstreamMarshaller" !class="org.springframework.oxm.xstream.XStreamMarshaller">! <property name="aliases">! <props>! <prop key=“Customer">mypackage.Customer</prop>! </props>! !</property>! </bean>! ...! </beans>!
  • 23. Spring MVC @Controller @RequestMapping @PathVariable
  • 24. @Controller The C of MVC <context:component- scan/> Mapping to an URI (optional)
  • 25. @RequestMapping Mapping a Controller or Methods to an URI URI-Pattern Mapping to a HTTP- Method Works with @PathVariable
  • 26. @Controller! @RequestMapping(„/customer“)! public class CustomerController{! !@RequestMapping(method=RequestMethod.GET)! !public List<Customer> list(){! ! !return customerList;! !}! }!
  • 27. @Controller! @RequestMapping(„/customer“)! public class CustomerController{! !@RequestMapping(value=„/list“,! ! ! ! method=RequestMethod.GET)! !public List<Customer> list(){! ! !return customerList;! !}! }!
  • 28. @Controller! @RequestMapping(„/customer“)! public class CustomerController{! !@RequestMapping(value=„/show/{customerId}“,! ! ! ! method=RequestMethod.GET)! !public Customer show(! ! @PathVariable(„customerId“) long customerId){! ! !return customer;! !}! }!
  • 29. @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:...“;! !}! }!
  • 30. RestTemplate Delete Get Head Options Post Put
  • 31. 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! public void displayHeaderInfo(! @RequestHeader("Accept-Encoding") String encoding,! @RequestHeader("Keep-Alive") long keepAlive) {! !...! }!
  • 32. JSR-303 public class VistorForm(! !@NotNull! @Size(max=40)! !private String name;! !@Min(18)! !private int age;! }! <bean id="validator" ! !class=“...LocalValidatorFactoryBean" />!
  • 33. HSQL H2 Derby ...
  • 34. <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();!
  • 35. 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();! }! }!
  • 36. @Async (out of EJB 3.1) JSR-303 JSF 2.0 JPA 2
  • 37. • Spring project, • OSGi bundle • Support for all the Spring Application Tools OSGi Flexible Deployments bean and XML file overview and most common wizards visual dependency Java EE • Graphical Spring graph application configuration • Classpath servers editor management • Advanced support • Spring 3.0 support based on OSGi for SpringSource including meta data dm Server @Configuration • Automatic • Advanced support and @Bean styles generation of for SpringSource • Spring Web Flow manifest tc Server and Spring Batch dependency meta • Cloud Foundry visual data targeting for dm development tools • SpringSource Server and tc • Spring Roo project Enterprise Bundle Server wizard and Repository • VMware Lab development shell browser Manager and • Spring • Manifest file Workstation Application blue validation and integration and prints and best best practice deployment practice validation recommendations
  • 38. Grails for Spring Best AOP-driven Java Practices Nice Test-driven Console
  • 39. @Roo* Command AspectJ Annotations Line Shell Intertype Metadata RoundTrip (Source- Declarations Level)
  • 40. 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
  • 41. Roo for Best Groovy- Groovy Practices driven Test- Nice driven Console
  • 42. Have your next Web 2.0 Get instant feedback, Powered by Spring, project done in weeks See instant results. Grails out performs the instead of months. Grails is the premier competition. Dynamic, Grails delivers a new dynamic language agile web development age of Java web web framework for the without compromises. application productivity. JVM. Rapid Dynamic Robust
  • 43. Support Grails Project Project Wizard different Grails Converter Versions Grails Full Groovy Grails Tooling Command Support Prompt
  • 44. CTRL+ALT+G (or CMD+ALT+G on Macs)
  • 45. >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!
  • 46. •  http://www.springframework.org/ Spring •  http://www.springsource.com/ Grails & •  http://www.grails.org/ •  http://groovy.codehaus.org/ Groovy •  http://www.thorsten-kamann.de Extras •  http://www.itemis.de